Skip to content

Commit

Permalink
Refactor changes_since to have a handle_results function argument
Browse files Browse the repository at this point in the history
Summary:
# Context

We are introducing EdenFS notifications to support scalable and ergonomic file system notifications for EdenFS mounts.

# This Diff
This diff implements some setup for the subscribe functionality

# Technical Details
Refactor subscribe to take in a handle_results function argument. This will allow client-specified handling of the results object from ChangesSinceV2

# Discussion Points

Reviewed By: jdelliot

Differential Revision: D68795884

fbshipit-source-id: b47f94c39a6f9053f56f8006de173c9414fbe343
  • Loading branch information
Chris Dinh authored and facebook-github-bot committed Jan 31, 2025
1 parent 9b88334 commit 8dbbe8c
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions eden/fs/cli_rs/edenfs-commands/src/notify/changes_since.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ use std::path::PathBuf;
use anyhow::Result;
use async_trait::async_trait;
use clap::Parser;
use edenfs_client::types::ChangesSinceV2Result;
use edenfs_client::types::JournalPosition;
use edenfs_client::EdenFsInstance;
use edenfs_error::EdenFsError;
use edenfs_error::ResultExt;
use hg_util::path::expand_path;

use crate::ExitCode;
Expand Down Expand Up @@ -73,6 +76,21 @@ pub struct ChangesSinceCmd {
json: bool,
}

impl ChangesSinceCmd {
fn print_result(&self, result: &ChangesSinceV2Result) -> Result<(), EdenFsError> {
println!(
"{}",
if self.json {
serde_json::to_string(&result).from_err()? + "\n"
} else {
result.to_string()
}
);

Ok(())
}
}

#[async_trait]
impl crate::Subcommand for ChangesSinceCmd {
#[cfg(not(fbcode_build))]
Expand Down Expand Up @@ -101,15 +119,8 @@ impl crate::Subcommand for ChangesSinceCmd {
None,
)
.await?;
println!(
"{}",
if self.json {
serde_json::to_string(&result)?
} else {
result.to_string()
}
);

self.print_result(&result)?;
if self.subscribe {
println!("Getting changes since {}", result.to_position);
}
Expand Down

0 comments on commit 8dbbe8c

Please sign in to comment.