mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-07 03:55:28 +00:00
chore: remove comments
This commit is contained in:
parent
8eb973d470
commit
dd6718bd3b
49
src/cli.rs
49
src/cli.rs
@ -37,8 +37,8 @@ pub fn parse_args() -> crate::Result<ParsedArgs> {
|
|||||||
match &mut parsed_args.command {
|
match &mut parsed_args.command {
|
||||||
Command::Compress { files, .. } | Command::Decompress { files, .. } => {
|
Command::Compress { files, .. } | Command::Decompress { files, .. } => {
|
||||||
*files = canonicalize_files(&files)?;
|
*files = canonicalize_files(&files)?;
|
||||||
},
|
}
|
||||||
_ => {},
|
_ => {}
|
||||||
}
|
}
|
||||||
Ok(parsed_args)
|
Ok(parsed_args)
|
||||||
}
|
}
|
||||||
@ -72,7 +72,7 @@ fn canonicalize(path: impl AsRef<Path>) -> crate::Result<PathBuf> {
|
|||||||
} else {
|
} else {
|
||||||
Err(io_err.into())
|
Err(io_err.into())
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,7 +107,7 @@ pub fn parse_args_from(mut args: Vec<OsString>) -> crate::Result<ParsedArgs> {
|
|||||||
|
|
||||||
let command = Command::Compress { files, compressed_output_path };
|
let command = Command::Compress { files, compressed_output_path };
|
||||||
ParsedArgs { command, flags }
|
ParsedArgs { command, flags }
|
||||||
},
|
}
|
||||||
// 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"));
|
||||||
@ -130,7 +130,7 @@ pub fn parse_args_from(mut args: Vec<OsString>) -> crate::Result<ParsedArgs> {
|
|||||||
|
|
||||||
let command = Command::Decompress { files, output_folder };
|
let command = Command::Decompress { files, output_folder };
|
||||||
ParsedArgs { command, flags }
|
ParsedArgs { command, flags }
|
||||||
},
|
}
|
||||||
_ => unreachable!("You should match each subcommand passed."),
|
_ => unreachable!("You should match each subcommand passed."),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -157,14 +157,20 @@ mod tests {
|
|||||||
assert_eq!(test_cli("--help").unwrap().command, Command::ShowHelp);
|
assert_eq!(test_cli("--help").unwrap().command, Command::ShowHelp);
|
||||||
assert_eq!(test_cli("--version").unwrap().command, Command::ShowVersion);
|
assert_eq!(test_cli("--version").unwrap().command, Command::ShowVersion);
|
||||||
assert_eq!(test_cli("--version").unwrap().flags, oof::Flags::default());
|
assert_eq!(test_cli("--version").unwrap().flags, oof::Flags::default());
|
||||||
assert_eq!(test_cli("foo.zip bar.zip").unwrap().command, Command::Decompress {
|
assert_eq!(
|
||||||
files: vec!["foo.zip".into(), "bar.zip".into()],
|
test_cli("foo.zip bar.zip").unwrap().command,
|
||||||
output_folder: None
|
Command::Decompress {
|
||||||
});
|
files: vec!["foo.zip".into(), "bar.zip".into()],
|
||||||
assert_eq!(test_cli("compress foo bar baz.zip").unwrap().command, Command::Compress {
|
output_folder: None
|
||||||
files: vec!["foo".into(), "bar".into()],
|
}
|
||||||
compressed_output_path: "baz.zip".into()
|
);
|
||||||
});
|
assert_eq!(
|
||||||
|
test_cli("compress foo bar baz.zip").unwrap().command,
|
||||||
|
Command::Compress {
|
||||||
|
files: vec!["foo".into(), "bar".into()],
|
||||||
|
compressed_output_path: "baz.zip".into()
|
||||||
|
}
|
||||||
|
);
|
||||||
assert_eq!(test_cli("compress").unwrap_err(), crate::Error::MissingArgumentsForCompression);
|
assert_eq!(test_cli("compress").unwrap_err(), crate::Error::MissingArgumentsForCompression);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,15 +180,12 @@ mod tests {
|
|||||||
assert_eq!(test_cli("--help").unwrap().flags, oof::Flags::default());
|
assert_eq!(test_cli("--help").unwrap().flags, oof::Flags::default());
|
||||||
assert_eq!(test_cli("--version").unwrap().flags, oof::Flags::default());
|
assert_eq!(test_cli("--version").unwrap().flags, oof::Flags::default());
|
||||||
|
|
||||||
// Just for reference:
|
assert_eq!(
|
||||||
// pub struct Flags {
|
test_cli("foo --yes bar --output folder").unwrap().flags,
|
||||||
// pub boolean_flags: BTreeSet<&'static str>,
|
oof::Flags {
|
||||||
// pub argument_flags: BTreeMap<&'static str, OsString>,
|
boolean_flags: vec!["yes"].into_iter().collect(),
|
||||||
// }
|
argument_flags: vec![("output", OsString::from("folder"))].into_iter().collect(),
|
||||||
|
}
|
||||||
assert_eq!(test_cli("foo --yes bar --output folder").unwrap().flags, oof::Flags {
|
);
|
||||||
boolean_flags: vec!["yes"].into_iter().collect(),
|
|
||||||
argument_flags: vec![("output", OsString::from("folder"))].into_iter().collect(),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user