1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

Use time-style only if time is provided

This commit is contained in:
Carbrex 2024-04-01 16:48:19 +05:30 committed by Sylvestre Ledru
parent ffda2a4b40
commit 49c7e65f5d
2 changed files with 17 additions and 2 deletions

View file

@ -721,6 +721,12 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
excludes: build_exclude_patterns(&matches)?, excludes: build_exclude_patterns(&matches)?,
}; };
let time_format = if time.is_some() {
parse_time_style(matches.get_one::<String>("time-style").map(|s| s.as_str()))?.to_string()
} else {
"%Y-%m-%d %H:%M".to_string()
};
let stat_printer = StatPrinter { let stat_printer = StatPrinter {
max_depth, max_depth,
size_format, size_format,
@ -737,8 +743,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
.transpose()?, .transpose()?,
apparent_size: matches.get_flag(options::APPARENT_SIZE) || matches.get_flag(options::BYTES), apparent_size: matches.get_flag(options::APPARENT_SIZE) || matches.get_flag(options::BYTES),
time, time,
time_format: parse_time_style(matches.get_one::<String>("time-style").map(|s| s.as_str()))? time_format,
.to_string(),
line_ending: LineEnding::from_zero_flag(matches.get_flag(options::NULL)), line_ending: LineEnding::from_zero_flag(matches.get_flag(options::NULL)),
}; };

View file

@ -1116,3 +1116,13 @@ fn test_du_files0_from_combined() {
assert!(stderr.contains("file operands cannot be combined with --files0-from")); assert!(stderr.contains("file operands cannot be combined with --files0-from"));
} }
#[test]
fn test_invalid_time_style() {
let ts = TestScenario::new(util_name!());
ts.ucmd()
.arg("-s")
.arg("--time-style=banana")
.succeeds()
.stdout_does_not_contain("du: invalid argument 'banana' for 'time style'");
}