Skip to content

Commit ccd0cf2

Browse files
jdelliotfacebook-github-bot
authored andcommitted
Add PrefetchCmd - not yet implemented
Summary: # This Diff Add PrefetchCmd - not yet implemented # Context We are doing some Oxidation (Python->Rust) migration of the EdenFS CLI. This is an ongoing BE activity that will complete when all CLI commands have been moved. Reviewed By: genevievehelsel Differential Revision: D75483516 fbshipit-source-id: e24d0bf6019c9ef33a1f5cdf5bcbc8a3218c6eb3
1 parent 53f340b commit ccd0cf2

File tree

3 files changed

+92
-1
lines changed

3 files changed

+92
-1
lines changed

eden/fs/cli_rs/edenfs-commands/src/glob_and_prefetch.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@
77

88
mod common;
99
pub mod glob;
10+
pub mod prefetch;
1011

1112
pub use glob::*;
13+
pub use prefetch::*;
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This software may be used and distributed according to the terms of the
5+
* GNU General Public License version 2.
6+
*/
7+
8+
//! edenfsctl glob
9+
10+
use std::path::PathBuf;
11+
12+
use anyhow::Context;
13+
use anyhow::Result;
14+
use async_trait::async_trait;
15+
use clap::Parser;
16+
use edenfs_client::glob_files::Glob;
17+
use edenfs_client::utils::locate_repo_root;
18+
19+
use crate::ExitCode;
20+
use crate::get_edenfs_instance;
21+
use crate::glob_and_prefetch::common::CommonArgs;
22+
23+
#[derive(Parser, Debug)]
24+
#[clap(
25+
about = "Prefetch content for matching file patterns. Glob patterns can be provided via a pattern file. This command does not do any filtering based on source control state or gitignore files."
26+
)]
27+
pub struct PrefetchCmd {
28+
#[clap(flatten)]
29+
common: CommonArgs,
30+
31+
#[clap(
32+
long,
33+
help = "DEPRECATED: Do not print the names of the matching files"
34+
)]
35+
silent: bool,
36+
37+
#[clap(long, help = "Do not prefetch files; only prefetch directories")]
38+
directories_only: bool,
39+
40+
#[clap(long, help = "Run the prefetch in the background")]
41+
background: bool,
42+
43+
#[clap(
44+
long,
45+
help = "Print the paths being prefetched. Does not work if using --background"
46+
)]
47+
debug_print: bool,
48+
}
49+
50+
impl PrefetchCmd {
51+
fn _print_result(&self, _result: &Glob) -> Result<()> {
52+
Ok(())
53+
}
54+
}
55+
56+
#[async_trait]
57+
impl crate::Subcommand for PrefetchCmd {
58+
async fn run(&self) -> Result<ExitCode> {
59+
// TODO: add in telemetry support
60+
let instance = get_edenfs_instance();
61+
let _client = instance.get_client();
62+
63+
// Get cwd mount_point if not provided.
64+
let current_dir: PathBuf;
65+
let mount_point = match &self.common.mount_point {
66+
Some(ref mount_point) => mount_point,
67+
None => {
68+
current_dir = std::env::current_dir()
69+
.context("Unable to retrieve current working directory")?;
70+
&current_dir
71+
}
72+
};
73+
74+
// Get mount_point as just repo root
75+
let _repo_root = locate_repo_root(mount_point);
76+
77+
// Load patterns
78+
let _patterns = self.common.load_patterns()?;
79+
80+
// TODO: invoke prefetch or glob based on params and fallback
81+
82+
Ok(0)
83+
}
84+
}

eden/fs/cli_rs/edenfs-commands/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ use hg_util::path::expand_path;
2525
use tracing::Level;
2626
use tracing::event;
2727

28+
use crate::gc::GcCmd;
29+
2830
mod config;
2931
mod debug;
3032
mod du;
@@ -48,7 +50,7 @@ mod util;
4850

4951
// Used to determine whether we should gate off certain oxidized edenfsctl commands
5052
const ROLLOUT_JSON: &str = "edenfsctl_rollout.json";
51-
const EXPERIMENTAL_COMMANDS: &[&str] = &["glob", "remove"];
53+
const EXPERIMENTAL_COMMANDS: &[&str] = &["glob", "prefetch", "remove"];
5254

5355
// We create a single EdenFsInstance when starting up
5456
static EDENFS_INSTANCE: OnceLock<EdenFsInstance> = OnceLock::new();
@@ -154,6 +156,7 @@ pub enum TopLevelSubcommand {
154156
#[cfg(target_os = "macos")]
155157
FileAccessMonitor(crate::file_access_monitor::FileAccessMonitorCmd),
156158
Glob(crate::glob_and_prefetch::GlobCmd),
159+
Prefetch(crate::glob_and_prefetch::PrefetchCmd),
157160
}
158161

159162
impl TopLevelSubcommand {
@@ -183,6 +186,7 @@ impl TopLevelSubcommand {
183186
#[cfg(target_os = "macos")]
184187
FileAccessMonitor(cmd) => cmd,
185188
Glob(cmd) => cmd,
189+
Prefetch(cmd) => cmd,
186190
}
187191
}
188192

@@ -212,6 +216,7 @@ impl TopLevelSubcommand {
212216
#[cfg(target_os = "macos")]
213217
TopLevelSubcommand::FileAccessMonitor(_) => "file-access-monitor",
214218
TopLevelSubcommand::Glob(_) => "glob",
219+
TopLevelSubcommand::Prefetch(_) => "prefetch",
215220
}
216221
}
217222
}

0 commit comments

Comments
 (0)