From b614533fd5935792dcb2056f15b5949247893c36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Miguel?= Date: Thu, 8 Apr 2021 22:31:10 -0300 Subject: [PATCH 1/4] utils: fix usage of the -n, --no flag --- src/utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils.rs b/src/utils.rs index 99020aa..011d3ed 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -105,7 +105,7 @@ pub fn permission_for_overwriting( flags: &oof::Flags, confirm: &Confirmation, ) -> crate::Result { - match (flags.is_present("yes"), flags.is_present("false")) { + match (flags.is_present("yes"), flags.is_present("no")) { (true, true) => { unreachable!("This should've been cutted out in the ~/src/cli.rs filter flags function.") } From 38e7009a27753d0f2186424e960a7b411ec9f4d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Miguel?= Date: Thu, 8 Apr 2021 22:46:47 -0300 Subject: [PATCH 2/4] cli: add an alias for the compress subcommand --- src/cli.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 1fdcaa3..5602966 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -94,12 +94,14 @@ pub fn parse_args_from(mut args: Vec) -> crate::Result { }); } - let subcommands = &["compress"]; + let subcommands = &[ + "c", "compress" + ]; let mut flags_info = vec![flag!('y', "yes"), flag!('n', "no")]; let parsed_args = match oof::pop_subcommand(&mut args, subcommands) { - Some(&"compress") => { + Some(&"c") | Some(&"compress") => { // `ouch compress` subcommand let (args, flags) = oof::filter_flags(args, &flags_info)?; let mut files: Vec = args.into_iter().map(PathBuf::from).collect(); From 3cb0bfa1e570d27db2833ee3ec288606178c6c26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Miguel?= Date: Fri, 9 Apr 2021 02:05:31 -0300 Subject: [PATCH 3/4] cli: refactor path canonicalizing logic --- src/cli.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 5602966..43fddd8 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -135,13 +135,10 @@ pub fn parse_args_from(mut args: Vec) -> crate::Result { // Parse flags let (args, mut flags) = oof::filter_flags(args, &flags_info)?; - let files = args.into_iter().map(canonicalize); - for file in files.clone() { - if let Err(err) = file { - return Err(err); - } - } - let files = files.map(Result::unwrap).collect(); + let files = args + .into_iter() + .map(canonicalize) + .collect::, _>>()?; let output_folder = flags.take_arg("output").map(PathBuf::from); From 2ba91644e854429c6f0090e6529278c3879c7f1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Miguel?= Date: Fri, 9 Apr 2021 12:05:49 -0300 Subject: [PATCH 4/4] commands: remove two unnecessary clones --- src/commands.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index ad5dee8..10ef89c 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -49,7 +49,7 @@ type BoxedDecompressor = Box; fn get_compressor(file: &File) -> crate::Result<(Option, BoxedCompressor)> { let extension = match &file.extension { - Some(extension) => extension.clone(), + Some(extension) => extension, None => { // This is reached when the output file given does not have an extension or has an unsupported one return Err(crate::Error::MissingExtensionError(file.path.to_path_buf())); @@ -58,7 +58,7 @@ fn get_compressor(file: &File) -> crate::Result<(Option, BoxedC // Supported first compressors: // .tar and .zip - let first_compressor: Option> = match extension.first_ext { + let first_compressor: Option> = match &extension.first_ext { Some(ext) => match ext { CompressionFormat::Tar => Some(Box::new(TarCompressor)), CompressionFormat::Zip => Some(Box::new(ZipCompressor)), @@ -84,7 +84,7 @@ fn get_compressor(file: &File) -> crate::Result<(Option, BoxedC fn get_decompressor(file: &File) -> crate::Result<(Option, BoxedDecompressor)> { let extension = match &file.extension { - Some(extension) => extension.clone(), + Some(extension) => extension, None => { // This block *should* be unreachable eprintln!( @@ -104,7 +104,7 @@ fn get_decompressor(file: &File) -> crate::Result<(Option, Bo CompressionFormat::Bzip => Box::new(BzipDecompressor), }; - let first_decompressor: Option> = match extension.first_ext { + let first_decompressor: Option> = match &extension.first_ext { Some(ext) => match ext { CompressionFormat::Tar => Some(Box::new(TarDecompressor)), CompressionFormat::Zip => Some(Box::new(ZipDecompressor)),