From d3b0e3e93f4636bb6cceb148536c914106e486f7 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Sun, 6 Aug 2023 20:23:50 +0200 Subject: Improve the -d flag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now when performing a dry run, you are shown the direct move from src to dst. This is a lot more helpful since the end user doesn’t really care about whatever temporary folder we store things in; the user just wants to make sure the command he’s about to execute will do what he expects. --- src/main.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 23a0bf6..cca7c87 100644 --- a/src/main.rs +++ b/src/main.rs @@ -156,11 +156,17 @@ fn work() -> Result<(), io::Error> { come first. */ ps.sort_by_key(|s| Reverse(s.0.components().count())); - for (s, t, _) in ps.iter() { - move_path(&flags, &s, &t); - } - for (_, t, d) in ps.iter().rev() { - move_path(&flags, &t, &d); + if flags.dryrun { + for (s, _, d) in ps { + println!("{} -> {}", s.as_path().display(), d.as_path().display()); + } + } else { + for (s, t, _) in ps.iter() { + move_path(&flags, &s, &t); + } + for (_, t, d) in ps.iter().rev() { + move_path(&flags, &t, &d); + } } Ok(()) @@ -175,10 +181,7 @@ fn parse_args() -> Result<(Flags, Vec), lexopt::Error> { while let Some(arg) = parser.next()? { match arg { Short('0') | Long("nul") => flags.nul = true, - Short('d') | Long("dryrun") => { - flags.dryrun = true; - flags.verbose = true; - } + Short('d') | Long("dryrun") => flags.dryrun = true, Short('e') | Long("encode") => flags.encode = true, Short('i') | Long("individual") => flags.individual = true, Short('v') | Long("verbose") => flags.verbose = true, -- cgit v1.2.3