|
| 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 | + ¤t_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 | +} |
0 commit comments