mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 19:47:45 +00:00
Merge pull request #3414 from gmnsii/main
df: -h -H shouldn't cause an error #3366
This commit is contained in:
commit
d7cf3e7483
2 changed files with 73 additions and 6 deletions
|
@ -346,6 +346,7 @@ impl fmt::Display for DfError {
|
|||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let matches = uu_app().get_matches_from(args);
|
||||
|
||||
#[cfg(windows)]
|
||||
{
|
||||
if matches.is_present(OPT_INODES) {
|
||||
|
@ -406,6 +407,7 @@ pub fn uu_app<'a>() -> Command<'a> {
|
|||
Arg::new(OPT_ALL)
|
||||
.short('a')
|
||||
.long("all")
|
||||
.overrides_with(OPT_ALL)
|
||||
.help("include dummy file systems"),
|
||||
)
|
||||
.arg(
|
||||
|
@ -413,6 +415,7 @@ pub fn uu_app<'a>() -> Command<'a> {
|
|||
.short('B')
|
||||
.long("block-size")
|
||||
.takes_value(true)
|
||||
.overrides_with_all(&[OPT_KILO, OPT_BLOCKSIZE])
|
||||
.help(
|
||||
"scale sizes by SIZE before printing them; e.g.\
|
||||
'-BM' prints sizes in units of 1,048,576 bytes",
|
||||
|
@ -421,39 +424,47 @@ pub fn uu_app<'a>() -> Command<'a> {
|
|||
.arg(
|
||||
Arg::new(OPT_TOTAL)
|
||||
.long("total")
|
||||
.overrides_with(OPT_TOTAL)
|
||||
.help("produce a grand total"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(OPT_HUMAN_READABLE_BINARY)
|
||||
.short('h')
|
||||
.long("human-readable")
|
||||
.conflicts_with(OPT_HUMAN_READABLE_DECIMAL)
|
||||
.overrides_with_all(&[OPT_HUMAN_READABLE_DECIMAL, OPT_HUMAN_READABLE_BINARY])
|
||||
.help("print sizes in human readable format (e.g., 1K 234M 2G)"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(OPT_HUMAN_READABLE_DECIMAL)
|
||||
.short('H')
|
||||
.long("si")
|
||||
.conflicts_with(OPT_HUMAN_READABLE_BINARY)
|
||||
.overrides_with_all(&[OPT_HUMAN_READABLE_BINARY, OPT_HUMAN_READABLE_DECIMAL])
|
||||
.help("likewise, but use powers of 1000 not 1024"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(OPT_INODES)
|
||||
.short('i')
|
||||
.long("inodes")
|
||||
.overrides_with(OPT_INODES)
|
||||
.help("list inode information instead of block usage"),
|
||||
)
|
||||
.arg(Arg::new(OPT_KILO).short('k').help("like --block-size=1K"))
|
||||
.arg(
|
||||
Arg::new(OPT_KILO)
|
||||
.short('k')
|
||||
.help("like --block-size=1K")
|
||||
.overrides_with_all(&[OPT_BLOCKSIZE, OPT_KILO]),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(OPT_LOCAL)
|
||||
.short('l')
|
||||
.long("local")
|
||||
.overrides_with(OPT_LOCAL)
|
||||
.help("limit listing to local file systems"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(OPT_NO_SYNC)
|
||||
.long("no-sync")
|
||||
.conflicts_with(OPT_SYNC)
|
||||
.overrides_with_all(&[OPT_SYNC, OPT_NO_SYNC])
|
||||
.help("do not invoke sync before getting usage info (default)"),
|
||||
)
|
||||
.arg(
|
||||
|
@ -477,12 +488,13 @@ pub fn uu_app<'a>() -> Command<'a> {
|
|||
Arg::new(OPT_PORTABILITY)
|
||||
.short('P')
|
||||
.long("portability")
|
||||
.overrides_with(OPT_PORTABILITY)
|
||||
.help("use the POSIX output format"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(OPT_SYNC)
|
||||
.long("sync")
|
||||
.conflicts_with(OPT_NO_SYNC)
|
||||
.overrides_with_all(&[OPT_NO_SYNC, OPT_SYNC])
|
||||
.help("invoke sync before getting usage info"),
|
||||
)
|
||||
.arg(
|
||||
|
@ -498,6 +510,7 @@ pub fn uu_app<'a>() -> Command<'a> {
|
|||
Arg::new(OPT_PRINT_TYPE)
|
||||
.short('T')
|
||||
.long("print-type")
|
||||
.overrides_with(OPT_PRINT_TYPE)
|
||||
.help("print file system type"),
|
||||
)
|
||||
.arg(
|
||||
|
|
|
@ -26,6 +26,44 @@ fn test_df_compatible_si() {
|
|||
new_ucmd!().arg("-aH").succeeds();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_df_arguments_override_themselves() {
|
||||
new_ucmd!().args(&["--help", "--help"]).succeeds();
|
||||
new_ucmd!().arg("-aa").succeeds();
|
||||
new_ucmd!()
|
||||
.args(&["--block-size=3000", "--block-size=1000"])
|
||||
.succeeds();
|
||||
new_ucmd!().args(&["--total", "--total"]).succeeds();
|
||||
new_ucmd!().arg("-hh").succeeds();
|
||||
new_ucmd!().arg("-HH").succeeds();
|
||||
new_ucmd!().arg("-ii").succeeds();
|
||||
new_ucmd!().arg("-kk").succeeds();
|
||||
new_ucmd!().arg("-ll").succeeds();
|
||||
new_ucmd!().args(&["--no-sync", "--no-sync"]).succeeds();
|
||||
new_ucmd!().arg("-PP").succeeds();
|
||||
new_ucmd!().args(&["--sync", "--sync"]).succeeds();
|
||||
new_ucmd!().arg("-TT").succeeds();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_df_conflicts_overriding() {
|
||||
new_ucmd!().arg("-hH").succeeds();
|
||||
new_ucmd!().arg("-Hh").succeeds();
|
||||
new_ucmd!().args(&["--no-sync", "--sync"]).succeeds();
|
||||
new_ucmd!().args(&["--sync", "--no-sync"]).succeeds();
|
||||
new_ucmd!().args(&["-k", "--block-size=3000"]).succeeds();
|
||||
new_ucmd!().args(&["--block-size=3000", "-k"]).succeeds();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_df_output_arg() {
|
||||
new_ucmd!().args(&["--output=source", "-iPT"]).fails();
|
||||
new_ucmd!().args(&["-iPT", "--output=source"]).fails();
|
||||
new_ucmd!()
|
||||
.args(&["--output=source", "--output=source"])
|
||||
.fails();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_df_output() {
|
||||
let expected = if cfg!(target_os = "macos") {
|
||||
|
@ -60,6 +98,22 @@ fn test_df_output() {
|
|||
assert_eq!(actual, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_df_output_overridden() {
|
||||
let expected = if cfg!(target_os = "macos") {
|
||||
"Filesystem Size Used Available Capacity Use% Mounted on "
|
||||
} else {
|
||||
"Filesystem Size Used Available Use% Mounted on "
|
||||
};
|
||||
let output = new_ucmd!()
|
||||
.arg("-hH")
|
||||
.arg("--total")
|
||||
.succeeds()
|
||||
.stdout_move_str();
|
||||
let actual = output.lines().take(1).collect::<Vec<&str>>()[0];
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_total_option_with_single_dash() {
|
||||
// These should fail because `-total` should have two dashes,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue