From a3004fbbff00703ac37938c42b4e07f227c0046b Mon Sep 17 00:00:00 2001 From: Jeremy Neptune Date: Fri, 15 Jul 2016 14:41:50 -0400 Subject: [PATCH] cp: added -v/--verbose flag I forgot that -v refers to "verbose" and not "version" when making earlier changes. So I fixed that and for good measure added the verbose flag anyway. --- src/cp/cp.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/cp/cp.rs b/src/cp/cp.rs index b3255dd9b..102f9eda3 100644 --- a/src/cp/cp.rs +++ b/src/cp/cp.rs @@ -34,9 +34,10 @@ pub fn uumain(args: Vec) -> i32 { let mut opts = Options::new(); opts.optflag("h", "help", "display this help and exit"); - opts.optflag("v", "version", "output version information and exit"); + opts.optflag("", "version", "output version information and exit"); opts.optopt("t", "target-directory", "copy all SOURCE arguments into DIRECTORY", "DEST"); opts.optflag("T", "no-target-directory", "Treat DEST as a regular file and not a directory"); + opts.optflag("v", "verbose", "explicitly state what is being done"); let matches = match opts.parse(&args[1..]) { Ok(m) => m, @@ -45,7 +46,6 @@ pub fn uumain(args: Vec) -> i32 { panic!() }, }; - let usage = opts.usage("Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY."); let mode = if matches.opt_present("version") { Mode::Version @@ -79,7 +79,7 @@ fn help(usage: &str) { } fn copy(matches: getopts::Matches) { - + let verbose = matches.opt_present("verbose"); let sources: Vec = if matches.free.is_empty() { show_error!("Missing SOURCE or DEST argument. Try --help."); panic!() @@ -136,6 +136,9 @@ fn copy(matches: getopts::Matches) { if dest.is_dir() { full_dest.push(source.file_name().unwrap()); //the destination path is the destination } // directory + the file name we're copying + if verbose { + println!("{} -> {}", source.display(), full_dest.display()); + } if let Err(err) = fs::copy(source, full_dest) { show_error!("{}", err); panic!(); @@ -157,7 +160,9 @@ fn copy(matches: getopts::Matches) { full_dest.push(source.file_name().unwrap()); - println!("{}", full_dest.display()); + if verbose { + println!("{} -> {}", source.display(), full_dest.display()); + } let io_result = fs::copy(source, full_dest);