mirror of
https://github.com/uutils/coreutils
synced 2024-12-14 07:12:44 +00:00
mktemp: match GNU error message on too many args
Update the usage message when too many template arguments are given on the command line to match that of GNU mktemp: mktemp: too many templates Try 'mktemp --help' for more information. This fixes the test case `too-many` in the GNU test suite file `tests/misc/mktemp.pl`.
This commit is contained in:
parent
9ed546b02c
commit
7b35749ea6
2 changed files with 15 additions and 3 deletions
|
@ -10,7 +10,7 @@
|
|||
|
||||
use clap::{crate_version, Arg, ArgMatches, Command};
|
||||
use uucore::display::{println_verbatim, Quotable};
|
||||
use uucore::error::{FromIo, UError, UResult};
|
||||
use uucore::error::{FromIo, UError, UResult, UUsageError};
|
||||
use uucore::format_usage;
|
||||
|
||||
use std::env;
|
||||
|
@ -327,7 +327,15 @@ impl Params {
|
|||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let args = args.collect_lossy();
|
||||
|
||||
let matches = uu_app().try_get_matches_from(&args)?;
|
||||
let matches = match uu_app().try_get_matches_from(&args) {
|
||||
Ok(m) => m,
|
||||
Err(e) => {
|
||||
if e.kind == clap::error::ErrorKind::TooManyValues && e.info[0] == "<template>..." {
|
||||
return Err(UUsageError::new(1, "too many templates"));
|
||||
}
|
||||
return Err(e.into());
|
||||
}
|
||||
};
|
||||
|
||||
// Parse command-line options into a format suitable for the
|
||||
// application logic.
|
||||
|
|
|
@ -613,7 +613,11 @@ fn test_too_few_xs_suffix_directory() {
|
|||
|
||||
#[test]
|
||||
fn test_too_many_arguments() {
|
||||
new_ucmd!().args(&["-q", "a", "b"]).fails().code_is(1);
|
||||
new_ucmd!()
|
||||
.args(&["-q", "a", "b"])
|
||||
.fails()
|
||||
.code_is(1)
|
||||
.usage_error("too many templates");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in a new issue