diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index a5fe3d624..2aa4bad06 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 c9f43028c..179941e78 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!());