ls: fix exit code for --time-style when used

This commit is contained in:
Ben Wiederhake 2024-04-01 04:41:24 +02:00
parent 4a1bd78f48
commit 714b4ff589
2 changed files with 31 additions and 1 deletions

View file

@ -966,7 +966,12 @@ impl Config {
let mut quoting_style = extract_quoting_style(options, show_control);
let indicator_style = extract_indicator_style(options);
let time_style = parse_time_style(options)?;
// Only parse the value to "--time-style" if it will become relevant.
let time_style = if format == Format::Long {
parse_time_style(options)?
} else {
TimeStyle::Iso
};
let mut ignore_patterns: Vec<Pattern> = Vec::new();

View file

@ -86,6 +86,31 @@ fn test_invalid_value_returns_2() {
}
}
#[test]
fn test_invalid_value_time_style() {
// This is the only flag which does not raise an error if it is invalid but not actually used:
new_ucmd!()
.arg("--time-style=definitely_invalid_value")
.succeeds()
.no_stderr()
.code_is(0);
// If it is used, error:
new_ucmd!()
.arg("-g")
.arg("--time-style=definitely_invalid_value")
.fails()
.no_stdout()
.code_is(2);
// If it only looks temporarily like it might be used, no error:
new_ucmd!()
.arg("-l")
.arg("--time-style=definitely_invalid_value")
.arg("--format=single-column")
.succeeds()
.no_stderr()
.code_is(0);
}
#[test]
fn test_ls_ls() {
new_ucmd!().succeeds();