1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 19:47:45 +00:00

base32/64: print the first extra operand, not the one before

Only one operand is allowed, so when there are multiple arguments we
should print the second argument in the error.
This commit is contained in:
Michael Debertol 2021-08-03 23:37:20 +02:00
parent 26cc2ed440
commit 44ae927969
3 changed files with 11 additions and 8 deletions

View file

@ -34,12 +34,15 @@ pub mod options {
}
impl Config {
fn from(options: clap::ArgMatches) -> Result<Config, String> {
fn from(app_name: &str, options: clap::ArgMatches) -> Result<Config, String> {
let file: Option<String> = match options.values_of(options::FILE) {
Some(mut values) => {
let name = values.next().unwrap();
if values.len() != 0 {
return Err(format!("extra operand '{}'", name));
if let Some(extra_op) = values.next() {
return Err(format!(
"extra operand '{}'\nTry '{} --help' for more information.",
extra_op, app_name
));
}
if name == "-" {
@ -82,7 +85,7 @@ pub fn parse_base_cmd_args(
let arg_list = args
.collect_str(InvalidEncodingHandling::ConvertLossy)
.accept_any();
Config::from(app.get_matches_from(arg_list))
Config::from(name, app.get_matches_from(arg_list))
}
pub fn base_app<'a>(name: &str, version: &'a str, about: &'a str) -> App<'static, 'a> {

View file

@ -112,9 +112,9 @@ fn test_base32_extra_operand() {
// Expect a failure when multiple files are specified.
new_ucmd!()
.arg("a.txt")
.arg("a.txt")
.arg("b.txt")
.fails()
.stderr_only("base32: extra operand 'a.txt'");
.stderr_only("base32: extra operand 'b.txt'");
}
#[test]

View file

@ -98,9 +98,9 @@ fn test_base64_extra_operand() {
// Expect a failure when multiple files are specified.
new_ucmd!()
.arg("a.txt")
.arg("a.txt")
.arg("b.txt")
.fails()
.stderr_only("base64: extra operand 'a.txt'");
.stderr_only("base64: extra operand 'b.txt'");
}
#[test]