mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-06 19:45:29 +00:00
cli: Only suggest the typo correction and exit
This commit is contained in:
parent
5ca99c101e
commit
c94b49f013
21
src/cli.rs
21
src/cli.rs
@ -6,7 +6,7 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use strsim::normalized_damerau_levenshtein;
|
use strsim::normalized_damerau_levenshtein;
|
||||||
use oof::{Flag, arg_flag, flag};
|
use oof::{arg_flag, flag};
|
||||||
|
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Debug)]
|
#[derive(PartialEq, Eq, Debug)]
|
||||||
@ -98,8 +98,10 @@ pub fn parse_args_from(mut args: Vec<OsString>) -> crate::Result<ParsedArgs> {
|
|||||||
|
|
||||||
let mut flags_info = vec![flag!('y', "yes"), flag!('n', "no")];
|
let mut flags_info = vec![flag!('y', "yes"), flag!('n', "no")];
|
||||||
|
|
||||||
let process_compression_command = |args, flags_info: Vec<Flag>| {
|
let parsed_args = match oof::pop_subcommand(&mut args, subcommands) {
|
||||||
let (args, flags) = oof::filter_flags(args, &flags_info)?;
|
Some(&"compress") => {
|
||||||
|
// `ouch compress` subcommand
|
||||||
|
let (args, flags) = oof::filter_flags(args, &flags_info)?;
|
||||||
let mut files: Vec<PathBuf> = args.into_iter().map(PathBuf::from).collect();
|
let mut files: Vec<PathBuf> = args.into_iter().map(PathBuf::from).collect();
|
||||||
|
|
||||||
if files.len() < 2 {
|
if files.len() < 2 {
|
||||||
@ -115,24 +117,15 @@ pub fn parse_args_from(mut args: Vec<OsString>) -> crate::Result<ParsedArgs> {
|
|||||||
files,
|
files,
|
||||||
compressed_output_path,
|
compressed_output_path,
|
||||||
};
|
};
|
||||||
Ok(ParsedArgs { command, flags })
|
ParsedArgs { command, flags }
|
||||||
};
|
|
||||||
|
|
||||||
let parsed_args = match oof::pop_subcommand(&mut args, subcommands) {
|
|
||||||
Some(&"compress") => {
|
|
||||||
process_compression_command(args, flags_info)?
|
|
||||||
}
|
}
|
||||||
// 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();
|
let first_arg = args.first().unwrap();
|
||||||
if is_typo(first_arg) {
|
if is_typo(first_arg) {
|
||||||
println!("Did you mean `ouch compress`?");
|
return Err(crate::Error::CompressionTypo);
|
||||||
// TODO: ask for permission ?
|
|
||||||
args.remove(0);
|
|
||||||
return process_compression_command(args, flags_info);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ pub enum Error {
|
|||||||
OofError,
|
OofError,
|
||||||
CompressingRootFolder,
|
CompressingRootFolder,
|
||||||
MissingArgumentsForCompression,
|
MissingArgumentsForCompression,
|
||||||
|
CompressionTypo,
|
||||||
WalkdirError,
|
WalkdirError,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,6 +79,9 @@ impl fmt::Display for Error {
|
|||||||
Error::IoError(io_err) => {
|
Error::IoError(io_err) => {
|
||||||
write!(f, "{}[ERROR]{} {}", colors::red(), colors::reset(), io_err)
|
write!(f, "{}[ERROR]{} {}", colors::red(), colors::reset(), io_err)
|
||||||
}
|
}
|
||||||
|
Error::CompressionTypo =>{
|
||||||
|
write!(f, "Did you mean {}ouch compress{}?", colors::magenta(), colors::reset())
|
||||||
|
}
|
||||||
_err => {
|
_err => {
|
||||||
// TODO
|
// TODO
|
||||||
write!(f, "")
|
write!(f, "")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user