mirror of
https://github.com/uutils/coreutils
synced 2024-12-13 23:02:38 +00:00
Merge pull request #3686 from cakebaker/show_error_if_padding_is_zero
numfmt: show error if --padding is zero
This commit is contained in:
commit
64bc20c2d8
2 changed files with 22 additions and 1 deletions
|
@ -103,7 +103,14 @@ fn parse_options(args: &ArgMatches) -> Result<NumfmtOptions> {
|
|||
let transform = TransformOptions { from, to };
|
||||
|
||||
let padding = match args.value_of(options::PADDING) {
|
||||
Some(s) => s.parse::<isize>().map_err(|err| err.to_string()),
|
||||
Some(s) => s
|
||||
.parse::<isize>()
|
||||
.map_err(|_| s)
|
||||
.and_then(|n| match n {
|
||||
0 => Err(s),
|
||||
_ => Ok(n),
|
||||
})
|
||||
.map_err(|s| format!("invalid padding value {}", s.quote())),
|
||||
None => Ok(0),
|
||||
}?;
|
||||
|
||||
|
|
|
@ -593,3 +593,17 @@ fn test_invalid_argument_returns_status_1() {
|
|||
.fails()
|
||||
.code_is(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_invalid_padding_value() {
|
||||
let padding_values = vec!["A", "0"];
|
||||
|
||||
for padding_value in padding_values {
|
||||
new_ucmd!()
|
||||
.arg(format!("--padding={}", padding_value))
|
||||
.arg("5")
|
||||
.fails()
|
||||
.code_is(1)
|
||||
.stderr_contains(format!("invalid padding value '{}'", padding_value));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue