mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07: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:
@@ -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> {
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user