diff --git a/src/cli.rs b/src/cli.rs index 43fddd8..886209a 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -5,9 +5,8 @@ use std::{ vec::Vec, }; -use strsim::normalized_damerau_levenshtein; use oof::{arg_flag, flag}; - +use strsim::normalized_damerau_levenshtein; #[derive(PartialEq, Eq, Debug)] pub enum Command { @@ -36,11 +35,10 @@ pub struct ParsedArgs { pub flags: oof::Flags, } - -/// check_for_typo checks if the first argument is -/// a typo for the compress subcommand. +/// check_for_typo checks if the first argument is +/// a typo for the compress subcommand. /// Returns true if the arg is probably a typo or false otherwise. -fn is_typo<'a, P>(path: P) -> bool +fn is_typo<'a, P>(path: P) -> bool where P: AsRef + 'a, { @@ -70,8 +68,6 @@ where } } - - fn canonicalize_files<'a, P>(files: Vec

) -> crate::Result> where P: AsRef + 'a, @@ -94,9 +90,7 @@ pub fn parse_args_from(mut args: Vec) -> crate::Result { }); } - let subcommands = &[ - "c", "compress" - ]; + let subcommands = &["c", "compress"]; let mut flags_info = vec![flag!('y', "yes"), flag!('n', "no")]; @@ -124,13 +118,14 @@ pub fn parse_args_from(mut args: Vec) -> crate::Result { // Defaults to decompression when there is no subcommand None => { flags_info.push(arg_flag!('o', "output")); - { - let first_arg = args.first().unwrap(); + + if let Some(first_arg) = args.first() { if is_typo(first_arg) { return Err(crate::Error::CompressionTypo); } + } else { + todo!("Complain that no decompression arguments were given."); } - // Parse flags let (args, mut flags) = oof::filter_flags(args, &flags_info)?;