From 6711dd569480c63ed1c6acb9de59b360a665a84c Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Mon, 11 Dec 2023 16:38:55 +0100 Subject: [PATCH 1/2] ls: make --block-size and --human-readable/--si override each other --- src/uu/ls/src/ls.rs | 6 +++-- tests/by-util/test_ls.rs | 50 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index a5fe3d6246d..2aa4bad067b 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -1552,7 +1552,7 @@ pub fn uu_app() -> Command { .short('h') .long(options::size::HUMAN_READABLE) .help("Print human readable file sizes (e.g. 1K 234M 56G).") - .overrides_with(options::size::SI) + .overrides_with_all([options::size::BLOCK_SIZE, options::size::SI]) .action(ArgAction::SetTrue), ) .arg( @@ -1569,6 +1569,7 @@ pub fn uu_app() -> Command { Arg::new(options::size::SI) .long(options::size::SI) .help("Print human readable file sizes using powers of 1000 instead of 1024.") + .overrides_with_all([options::size::BLOCK_SIZE, options::size::HUMAN_READABLE]) .action(ArgAction::SetTrue), ) .arg( @@ -1576,7 +1577,8 @@ pub fn uu_app() -> Command { .long(options::size::BLOCK_SIZE) .require_equals(true) .value_name("BLOCK_SIZE") - .help("scale sizes by BLOCK_SIZE when printing them"), + .help("scale sizes by BLOCK_SIZE when printing them") + .overrides_with_all([options::size::SI, options::size::HUMAN_READABLE]), ) .arg( Arg::new(options::INODE) diff --git a/tests/by-util/test_ls.rs b/tests/by-util/test_ls.rs index c9f43028c9c..179941e7878 100644 --- a/tests/by-util/test_ls.rs +++ b/tests/by-util/test_ls.rs @@ -3874,6 +3874,56 @@ fn test_ls_invalid_block_size() { .stderr_is("ls: invalid --block-size argument 'invalid'\n"); } +#[cfg(all(unix, feature = "dd"))] +#[test] +fn test_ls_block_size_override() { + let scene = TestScenario::new(util_name!()); + + scene + .ccmd("dd") + .arg("if=/dev/zero") + .arg("of=file") + .arg("bs=1024") + .arg("count=1") + .succeeds(); + + // --si "wins" + scene + .ucmd() + .arg("-s") + .arg("--block-size=512") + .arg("--si") + .succeeds() + .stdout_contains_line("total 4.1k"); + + // --block-size "wins" + scene + .ucmd() + .arg("-s") + .arg("--si") + .arg("--block-size=512") + .succeeds() + .stdout_contains_line("total 8"); + + // --human-readable "wins" + scene + .ucmd() + .arg("-s") + .arg("--block-size=512") + .arg("--human-readable") + .succeeds() + .stdout_contains_line("total 4.0K"); + + // --block-size "wins" + scene + .ucmd() + .arg("-s") + .arg("--human-readable") + .arg("--block-size=512") + .succeeds() + .stdout_contains_line("total 8"); +} + #[test] fn test_ls_hyperlink() { let scene = TestScenario::new(util_name!()); From 42558344f155f085acdc7b3b18e5a97fb479beb7 Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Tue, 12 Dec 2023 14:23:51 +0100 Subject: [PATCH 2/2] ls: enable "args override self" --- src/uu/ls/src/ls.rs | 1 + tests/by-util/test_ls.rs | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index 2aa4bad067b..1fceefe17fb 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -1070,6 +1070,7 @@ pub fn uu_app() -> Command { .about(ABOUT) .infer_long_args(true) .disable_help_flag(true) + .args_override_self(true) .arg( Arg::new(options::HELP) .long(options::HELP) diff --git a/tests/by-util/test_ls.rs b/tests/by-util/test_ls.rs index 179941e7878..c3460633a22 100644 --- a/tests/by-util/test_ls.rs +++ b/tests/by-util/test_ls.rs @@ -3924,6 +3924,21 @@ fn test_ls_block_size_override() { .stdout_contains_line("total 8"); } +#[test] +fn test_ls_block_size_override_self() { + new_ucmd!() + .arg("--block-size=512") + .arg("--block-size=512") + .succeeds(); + + new_ucmd!() + .arg("--human-readable") + .arg("--human-readable") + .succeeds(); + + new_ucmd!().arg("--si").arg("--si").succeeds(); +} + #[test] fn test_ls_hyperlink() { let scene = TestScenario::new(util_name!());