mirror of
https://github.com/uutils/coreutils.git
synced 2026-05-06 07:26:38 -04:00
pr: exit with code 1 if --column argument is zero (#11750)
This commit is contained in:
+11
-1
@@ -475,7 +475,7 @@ fn parse_usize(matches: &ArgMatches, opt: &str) -> Option<Result<usize, PrError>
|
||||
let i = value_to_parse.0;
|
||||
let option = value_to_parse.1;
|
||||
i.parse().map_err(|_e| PrError::EncounteredErrors {
|
||||
msg: format!("invalid {option} argument {}", i.quote()),
|
||||
msg: format!("invalid -{option} argument {}", i.quote()),
|
||||
})
|
||||
};
|
||||
matches
|
||||
@@ -771,6 +771,11 @@ fn build_options(
|
||||
})
|
||||
});
|
||||
let start_column_option = match res {
|
||||
Some(Ok(0)) => {
|
||||
return Err(PrError::EncounteredErrors {
|
||||
msg: "invalid --column argument '0'".to_string(),
|
||||
});
|
||||
}
|
||||
Some(res) => Some(res?),
|
||||
None => None,
|
||||
};
|
||||
@@ -778,6 +783,11 @@ fn build_options(
|
||||
// --column has more priority than -column
|
||||
|
||||
let column_option_value = match parse_usize(matches, options::COLUMN) {
|
||||
Some(Ok(0)) => {
|
||||
return Err(PrError::EncounteredErrors {
|
||||
msg: "invalid --column argument '0'".to_string(),
|
||||
});
|
||||
}
|
||||
Some(res) => Some(res?),
|
||||
None => start_column_option,
|
||||
};
|
||||
|
||||
@@ -873,3 +873,19 @@ fn test_expand_tab_does_not_consume_next_argument() {
|
||||
new_ucmd!().args(&["-ea", test_file_path]).succeeds();
|
||||
new_ucmd!().args(&["-ea1", test_file_path]).succeeds();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_zero_columns() {
|
||||
new_ucmd!()
|
||||
.arg("--column=0")
|
||||
.fails_with_code(1)
|
||||
.stderr_contains("pr: invalid --column argument '0'");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_zero_columns_shortcut() {
|
||||
new_ucmd!()
|
||||
.arg("-0")
|
||||
.fails_with_code(1)
|
||||
.stderr_contains("pr: invalid --column argument '0'");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user