mirror of
https://github.com/ouch-org/ouch.git
synced 2025-07-23 10:00:37 +00:00
decompression: panic if there are no arguments
This commit is contained in:
parent
8548f73870
commit
864fc1a29b
17
src/cli.rs
17
src/cli.rs
@ -5,9 +5,8 @@ use std::{
|
|||||||
vec::Vec,
|
vec::Vec,
|
||||||
};
|
};
|
||||||
|
|
||||||
use strsim::normalized_damerau_levenshtein;
|
|
||||||
use oof::{arg_flag, flag};
|
use oof::{arg_flag, flag};
|
||||||
|
use strsim::normalized_damerau_levenshtein;
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Debug)]
|
#[derive(PartialEq, Eq, Debug)]
|
||||||
pub enum Command {
|
pub enum Command {
|
||||||
@ -36,7 +35,6 @@ pub struct ParsedArgs {
|
|||||||
pub flags: oof::Flags,
|
pub flags: oof::Flags,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// check_for_typo checks if the first argument is
|
/// check_for_typo checks if the first argument is
|
||||||
/// a typo for the compress subcommand.
|
/// a typo for the compress subcommand.
|
||||||
/// Returns true if the arg is probably a typo or false otherwise.
|
/// Returns true if the arg is probably a typo or false otherwise.
|
||||||
@ -70,8 +68,6 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fn canonicalize_files<'a, P>(files: Vec<P>) -> crate::Result<Vec<PathBuf>>
|
fn canonicalize_files<'a, P>(files: Vec<P>) -> crate::Result<Vec<PathBuf>>
|
||||||
where
|
where
|
||||||
P: AsRef<Path> + 'a,
|
P: AsRef<Path> + 'a,
|
||||||
@ -94,9 +90,7 @@ pub fn parse_args_from(mut args: Vec<OsString>) -> crate::Result<ParsedArgs> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let subcommands = &[
|
let subcommands = &["c", "compress"];
|
||||||
"c", "compress"
|
|
||||||
];
|
|
||||||
|
|
||||||
let mut flags_info = vec![flag!('y', "yes"), flag!('n', "no")];
|
let mut flags_info = vec![flag!('y', "yes"), flag!('n', "no")];
|
||||||
|
|
||||||
@ -124,14 +118,15 @@ pub fn parse_args_from(mut args: Vec<OsString>) -> crate::Result<ParsedArgs> {
|
|||||||
// Defaults to decompression when there is no subcommand
|
// Defaults to decompression when there is no subcommand
|
||||||
None => {
|
None => {
|
||||||
flags_info.push(arg_flag!('o', "output"));
|
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) {
|
if is_typo(first_arg) {
|
||||||
return Err(crate::Error::CompressionTypo);
|
return Err(crate::Error::CompressionTypo);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
todo!("Complain that no decompression arguments were given.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Parse flags
|
// Parse flags
|
||||||
let (args, mut flags) = oof::filter_flags(args, &flags_info)?;
|
let (args, mut flags) = oof::filter_flags(args, &flags_info)?;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user