From 9b984345ab2e43f549e6df143be64da7fe12bafd Mon Sep 17 00:00:00 2001 From: Drew Short Date: Tue, 3 Mar 2020 21:36:09 -0600 Subject: [PATCH] Added dry-run global argument --- src/command/dedupe.rs | 9 ++++++--- src/main.rs | 7 +++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/command/dedupe.rs b/src/command/dedupe.rs index 0744628..1295a04 100644 --- a/src/command/dedupe.rs +++ b/src/command/dedupe.rs @@ -15,13 +15,16 @@ pub fn get_command<'a>() -> Command<'a, str>{ ) }) .runner(| _args, matches| { - // println!("Running dedupe, logging = {}", args); + let dry_run = matches.is_present("dry-run"); match matches.values_of("playlist") { Some(playlists) => { for path in playlists { let playlist = Playlist::read(path)?; - println!("{:?}", playlist); - playlist.write(path)? + if ! dry_run { + playlist.write(path)? + } else { + println!("{:?}", playlist); + } } Ok(()) }, diff --git a/src/main.rs b/src/main.rs index 93a93fe..6f41432 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,6 +22,13 @@ fn main() { .value_name("VERBOSITY") .help("Sets the logging verbosity, defaults to \"INFO\""), ) + .arg( + Arg::with_name("dry-run") + .long("dry-run") + .global(true) + .takes_value(false) + .help("Make no changes and print expected output") + ) }) .args(|_args, matches| matches.value_of("verbose").unwrap_or("INFO")) .add_cmd(command::dedupe::get_command())