From 00e94787e0e473f733b15da24ebe64ed0f595a9e Mon Sep 17 00:00:00 2001 From: diogo464 Date: Tue, 15 Feb 2022 18:27:30 +0000 Subject: improved status command allow specifying the paths that the status should be printed for instead of displaying everything --- src/dotup.rs | 15 +++++++++++---- src/main.rs | 9 ++++++--- 2 files changed, 17 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/dotup.rs b/src/dotup.rs index a7cccbe..296b182 100644 --- a/src/dotup.rs +++ b/src/dotup.rs @@ -287,11 +287,18 @@ impl Dotup { Ok(()) } - pub fn status(&self) { + pub fn status(&self, paths: impl Iterator>) { let status_result: anyhow::Result<()> = try { - let canonical_dir = utils::current_working_directory(); - let item = self.status_path_to_item(&canonical_dir)?; - self.status_print_item(item, 0)?; + // canonicalize and remove paths whose parent we already have + let paths = paths.map(utils::weakly_canonical).collect::>(); + let paths = paths + .iter() + .filter(|p| !paths.iter().any(|x| p.starts_with(x) && p != &x)); + + for path in paths { + let item = self.status_path_to_item(path)?; + self.status_print_item(item, 0)?; + } }; if let Err(e) = status_result { println!("error while displaying status : {e}"); diff --git a/src/main.rs b/src/main.rs index 132b418..acd0e38 100644 --- a/src/main.rs +++ b/src/main.rs @@ -214,10 +214,13 @@ fn command_mv(global_flags: Flags, args: MvArgs) -> anyhow::Result<()> { /// Shows information about links #[derive(Parser, Debug)] -struct StatusArgs {} +struct StatusArgs { + #[clap(default_value = ".")] + paths: Vec, +} -fn command_status(global_flags: Flags, _args: StatusArgs) -> anyhow::Result<()> { +fn command_status(global_flags: Flags, args: StatusArgs) -> anyhow::Result<()> { let dotup = utils::read_dotup(&global_flags)?; - dotup.status(); + dotup.status(args.paths.into_iter()); Ok(()) } -- cgit