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:
parent
26cc2ed440
commit
44ae927969
3 changed files with 11 additions and 8 deletions
|
@ -34,12 +34,15 @@ pub mod options {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
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) {
|
let file: Option<String> = match options.values_of(options::FILE) {
|
||||||
Some(mut values) => {
|
Some(mut values) => {
|
||||||
let name = values.next().unwrap();
|
let name = values.next().unwrap();
|
||||||
if values.len() != 0 {
|
if let Some(extra_op) = values.next() {
|
||||||
return Err(format!("extra operand '{}'", name));
|
return Err(format!(
|
||||||
|
"extra operand '{}'\nTry '{} --help' for more information.",
|
||||||
|
extra_op, app_name
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if name == "-" {
|
if name == "-" {
|
||||||
|
@ -82,7 +85,7 @@ pub fn parse_base_cmd_args(
|
||||||
let arg_list = args
|
let arg_list = args
|
||||||
.collect_str(InvalidEncodingHandling::ConvertLossy)
|
.collect_str(InvalidEncodingHandling::ConvertLossy)
|
||||||
.accept_any();
|
.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> {
|
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.
|
// Expect a failure when multiple files are specified.
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.arg("a.txt")
|
.arg("a.txt")
|
||||||
.arg("a.txt")
|
.arg("b.txt")
|
||||||
.fails()
|
.fails()
|
||||||
.stderr_only("base32: extra operand 'a.txt'");
|
.stderr_only("base32: extra operand 'b.txt'");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -98,9 +98,9 @@ fn test_base64_extra_operand() {
|
||||||
// Expect a failure when multiple files are specified.
|
// Expect a failure when multiple files are specified.
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.arg("a.txt")
|
.arg("a.txt")
|
||||||
.arg("a.txt")
|
.arg("b.txt")
|
||||||
.fails()
|
.fails()
|
||||||
.stderr_only("base64: extra operand 'a.txt'");
|
.stderr_only("base64: extra operand 'b.txt'");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue