aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordiogo464 <[email protected]>2022-02-15 18:27:30 +0000
committerdiogo464 <[email protected]>2022-02-15 18:27:30 +0000
commit00e94787e0e473f733b15da24ebe64ed0f595a9e (patch)
treecbcf21bdcaf67a54f88aa4b6be7f7d708fa00725
parent4b524a27edb8cd51f04bfc9bd79dfd17ab31003b (diff)
improved status command
allow specifying the paths that the status should be printed for instead of displaying everything
-rw-r--r--src/dotup.rs15
-rw-r--r--src/main.rs9
2 files changed, 17 insertions, 7 deletions
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 {
287 Ok(()) 287 Ok(())
288 } 288 }
289 289
290 pub fn status(&self) { 290 pub fn status(&self, paths: impl Iterator<Item = impl AsRef<Path>>) {
291 let status_result: anyhow::Result<()> = try { 291 let status_result: anyhow::Result<()> = try {
292 let canonical_dir = utils::current_working_directory(); 292 // canonicalize and remove paths whose parent we already have
293 let item = self.status_path_to_item(&canonical_dir)?; 293 let paths = paths.map(utils::weakly_canonical).collect::<HashSet<_>>();
294 self.status_print_item(item, 0)?; 294 let paths = paths
295 .iter()
296 .filter(|p| !paths.iter().any(|x| p.starts_with(x) && p != &x));
297
298 for path in paths {
299 let item = self.status_path_to_item(path)?;
300 self.status_print_item(item, 0)?;
301 }
295 }; 302 };
296 if let Err(e) = status_result { 303 if let Err(e) = status_result {
297 println!("error while displaying status : {e}"); 304 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<()> {
214 214
215/// Shows information about links 215/// Shows information about links
216#[derive(Parser, Debug)] 216#[derive(Parser, Debug)]
217struct StatusArgs {} 217struct StatusArgs {
218 #[clap(default_value = ".")]
219 paths: Vec<PathBuf>,
220}
218 221
219fn command_status(global_flags: Flags, _args: StatusArgs) -> anyhow::Result<()> { 222fn command_status(global_flags: Flags, args: StatusArgs) -> anyhow::Result<()> {
220 let dotup = utils::read_dotup(&global_flags)?; 223 let dotup = utils::read_dotup(&global_flags)?;
221 dotup.status(); 224 dotup.status(args.paths.into_iter());
222 Ok(()) 225 Ok(())
223} 226}