From 4d705621e648a7eb062d9fc84d693b72f08c65c4 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 22 Jun 2024 09:45:00 +0200 Subject: [PATCH] ls: --format will override the --dired option Closes: #6488 Co-authored-by: Daniel Hofstetter --- src/uu/ls/src/ls.rs | 6 ++++-- tests/by-util/test_ls.rs | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index 023b5e9f5..8db3f25b3 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -1083,7 +1083,7 @@ impl Config { // --dired implies --format=long format = Format::Long; } - if dired && format == Format::Long && options.get_flag(options::ZERO) { + if dired && options.get_flag(options::ZERO) { return Err(Box::new(LsError::DiredAndZeroAreIncompatible)); } @@ -1211,6 +1211,7 @@ pub fn uu_app() -> Command { options::format::LONG, options::format::ACROSS, options::format::COLUMNS, + options::DIRED, ]), ) .arg( @@ -1303,7 +1304,8 @@ pub fn uu_app() -> Command { .num_args(0..=1) .default_missing_value("always") .default_value("never") - .value_name("WHEN").overrides_with(options::DIRED), + .value_name("WHEN") + .overrides_with(options::DIRED), ) // The next four arguments do not override with the other format // options, see the comment in Config::from for the reason. diff --git a/tests/by-util/test_ls.rs b/tests/by-util/test_ls.rs index 8372d0f58..f8f638fd7 100644 --- a/tests/by-util/test_ls.rs +++ b/tests/by-util/test_ls.rs @@ -3969,6 +3969,28 @@ fn test_ls_dired_hyperlink() { .stdout_contains("//DIRED//"); } +#[test] +fn test_ls_dired_order_format() { + let scene = TestScenario::new(util_name!()); + let at = &scene.fixtures; + at.mkdir("dir"); + at.touch("dir/a"); + scene + .ucmd() + .arg("--dired") + .arg("--format=vertical") + .arg("-R") + .succeeds() + .stdout_does_not_contain("//DIRED//"); + scene + .ucmd() + .arg("--format=vertical") + .arg("--dired") + .arg("-R") + .succeeds() + .stdout_contains("//DIRED//"); +} + #[test] fn test_ls_dired_and_zero_are_incompatible() { let scene = TestScenario::new(util_name!());