From cd44a3d1fd5732d1cd2b631dfa6dec5577f1fbd1 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Fri, 21 Jun 2024 23:21:55 +0200 Subject: [PATCH] ls --dired: v9.5 --hyperlink is ignored if passed first Manages cases like: $ ls -R --dired --hyperlink a2 will show hyperlink $ ls -R --hyperlink --dired a2 won't --- src/uu/ls/src/ls.rs | 9 +++++---- tests/by-util/test_ls.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index b1117984c..023b5e9f5 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -1287,7 +1287,8 @@ pub fn uu_app() -> Command { .long(options::DIRED) .short('D') .help("generate output designed for Emacs' dired (Directory Editor) mode") - .action(ArgAction::SetTrue), + .action(ArgAction::SetTrue) + .overrides_with(options::HYPERLINK), ) .arg( Arg::new(options::HYPERLINK) @@ -1302,7 +1303,7 @@ pub fn uu_app() -> Command { .num_args(0..=1) .default_missing_value("always") .default_value("never") - .value_name("WHEN"), + .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. @@ -2018,7 +2019,7 @@ impl PathData { } fn show_dir_name(path_data: &PathData, out: &mut BufWriter, config: &Config) { - if config.hyperlink { + if config.hyperlink && !config.dired { let name = escape_name(&path_data.display_name, &config.quoting_style); let hyperlink = create_hyperlink(&name, path_data); write!(out, "{}:", hyperlink).unwrap(); @@ -2123,7 +2124,7 @@ pub fn list(locs: Vec<&Path>, config: &Config) -> UResult<()> { &mut style_manager, )?; } - if config.dired { + if config.dired && !config.hyperlink { dired::print_dired_output(config, &dired, &mut out)?; } Ok(()) diff --git a/tests/by-util/test_ls.rs b/tests/by-util/test_ls.rs index ce56868c5..8372d0f58 100644 --- a/tests/by-util/test_ls.rs +++ b/tests/by-util/test_ls.rs @@ -3941,6 +3941,34 @@ fn test_ls_dired_implies_long() { .stdout_contains("//DIRED-OPTIONS// --quoting-style"); } +#[test] +fn test_ls_dired_hyperlink() { + // we will have link but not the DIRED output + // note that the order matters + let scene = TestScenario::new(util_name!()); + let at = &scene.fixtures; + at.mkdir("dir"); + at.touch("dir/a"); + scene + .ucmd() + .arg("--dired") + .arg("--hyperlink") + .arg("-R") + .succeeds() + .stdout_contains("file://") + .stdout_does_not_contain("//DIRED//"); + // dired is passed after hyperlink + // so we will have DIRED output + scene + .ucmd() + .arg("--hyperlink") + .arg("--dired") + .arg("-R") + .succeeds() + .stdout_does_not_contain("file://") + .stdout_contains("//DIRED//"); +} + #[test] fn test_ls_dired_and_zero_are_incompatible() { let scene = TestScenario::new(util_name!());