mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
split: correct error message on invalid arg. to -a
Correct the error message displayed on an invalid parameter to the `--suffix-length` or `-a` command-line option.
This commit is contained in:
parent
1f7c08d87b
commit
e5361a8c11
2 changed files with 16 additions and 5 deletions
|
@ -233,12 +233,14 @@ struct Settings {
|
||||||
impl Settings {
|
impl Settings {
|
||||||
/// Parse a strategy from the command-line arguments.
|
/// Parse a strategy from the command-line arguments.
|
||||||
fn from(matches: &ArgMatches) -> UResult<Self> {
|
fn from(matches: &ArgMatches) -> UResult<Self> {
|
||||||
|
let suffix_length_str = matches.value_of(OPT_SUFFIX_LENGTH).unwrap();
|
||||||
let result = Self {
|
let result = Self {
|
||||||
suffix_length: matches
|
suffix_length: suffix_length_str.parse().map_err(|_| {
|
||||||
.value_of(OPT_SUFFIX_LENGTH)
|
USimpleError::new(
|
||||||
.unwrap()
|
1,
|
||||||
.parse()
|
format!("invalid suffix length: {}", suffix_length_str.quote()),
|
||||||
.unwrap_or_else(|_| panic!("Invalid number for {}", OPT_SUFFIX_LENGTH)),
|
)
|
||||||
|
})?,
|
||||||
numeric_suffix: matches.occurrences_of(OPT_NUMERIC_SUFFIXES) > 0,
|
numeric_suffix: matches.occurrences_of(OPT_NUMERIC_SUFFIXES) > 0,
|
||||||
additional_suffix: matches.value_of(OPT_ADDITIONAL_SUFFIX).unwrap().to_owned(),
|
additional_suffix: matches.value_of(OPT_ADDITIONAL_SUFFIX).unwrap().to_owned(),
|
||||||
verbose: matches.occurrences_of("verbose") > 0,
|
verbose: matches.occurrences_of("verbose") > 0,
|
||||||
|
|
|
@ -440,3 +440,12 @@ fn test_number() {
|
||||||
assert_eq!(file_read("xad"), "pqrst");
|
assert_eq!(file_read("xad"), "pqrst");
|
||||||
assert_eq!(file_read("xae"), "uvwxyz");
|
assert_eq!(file_read("xae"), "uvwxyz");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_invalid_suffix_length() {
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["-a", "xyz"])
|
||||||
|
.fails()
|
||||||
|
.no_stdout()
|
||||||
|
.stderr_contains("invalid suffix length: 'xyz'");
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue