ls: If we have --dired --hyperlink, we don't show dired but we still want to see the

long format

Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
This commit is contained in:
Sylvestre Ledru 2024-06-23 22:01:32 +02:00
parent 4d705621e6
commit ececddd672
3 changed files with 14 additions and 2 deletions

View file

@ -179,6 +179,14 @@ pub fn update_positions(dired: &mut DiredOutput, start: usize, end: usize) {
dired.padding = 0;
}
/// Checks if the "--dired" or "-D" argument is present in the command line arguments.
/// we don't use clap here because we need to know if the argument is present
/// as it can be overridden by --hyperlink
pub fn is_dired_arg_present() -> bool {
let args: Vec<String> = std::env::args().collect();
args.iter().any(|x| x == "--dired" || x == "-D")
}
#[cfg(test)]
mod tests {
use super::*;

View file

@ -67,7 +67,7 @@ use uucore::{
};
use uucore::{help_about, help_section, help_usage, parse_glob, show, show_error, show_warning};
mod dired;
use dired::DiredOutput;
use dired::{is_dired_arg_present, DiredOutput};
#[cfg(not(feature = "selinux"))]
static CONTEXT_HELP_TEXT: &str = "print any security context of each file (not enabled)";
#[cfg(feature = "selinux")]
@ -1079,8 +1079,10 @@ impl Config {
};
let dired = options.get_flag(options::DIRED);
if dired {
if dired || is_dired_arg_present() {
// --dired implies --format=long
// if we have --dired --hyperlink, we don't show dired but we still want to see the
// long format
format = Format::Long;
}
if dired && options.get_flag(options::ZERO) {

View file

@ -3956,6 +3956,8 @@ fn test_ls_dired_hyperlink() {
.arg("-R")
.succeeds()
.stdout_contains("file://")
.stdout_contains("-rw") // we should have the long output
// even if dired isn't actually run
.stdout_does_not_contain("//DIRED//");
// dired is passed after hyperlink
// so we will have DIRED output