diff --git a/src/uu/df/src/df.rs b/src/uu/df/src/df.rs index 48bd76041..55e2ca458 100644 --- a/src/uu/df/src/df.rs +++ b/src/uu/df/src/df.rs @@ -5,6 +5,7 @@ // // For the full copyright and license information, please view the LICENSE file // that was distributed with this source code. +// spell-checker:ignore itotal iused iavail ipcent pcent mod table; #[cfg(unix)] @@ -47,6 +48,10 @@ static OPT_SYNC: &str = "sync"; static OPT_TYPE: &str = "type"; static OPT_PRINT_TYPE: &str = "print-type"; static OPT_EXCLUDE_TYPE: &str = "exclude-type"; +static OUTPUT_FIELD_LIST: [&str; 12] = [ + "source", "fstype", "itotal", "iused", "iavail", "ipcent", "size", "used", "avail", "pcent", + "file", "target", +]; /// Store names of file systems as a selector. /// Note: `exclude` takes priority over `include`. @@ -355,6 +360,10 @@ pub fn uu_app<'a>() -> App<'a> { .long("output") .takes_value(true) .use_delimiter(true) + .possible_values(OUTPUT_FIELD_LIST) + .default_missing_values(&OUTPUT_FIELD_LIST) + .default_values(&["source", "size", "used", "avail", "pcent", "target"]) + .conflicts_with_all(&[OPT_INODES, OPT_PORTABILITY, OPT_PRINT_TYPE]) .help( "use the output format defined by FIELD_LIST,\ or print all fields if FIELD_LIST is omitted.", @@ -378,7 +387,7 @@ pub fn uu_app<'a>() -> App<'a> { .long("type") .allow_invalid_utf8(true) .takes_value(true) - .use_delimiter(true) + .multiple_occurrences(true) .help("limit listing to file systems of type TYPE"), ) .arg( diff --git a/tests/by-util/test_df.rs b/tests/by-util/test_df.rs index 00f1ecf3a..3af02428e 100644 --- a/tests/by-util/test_df.rs +++ b/tests/by-util/test_df.rs @@ -58,4 +58,23 @@ fn test_order_same() { assert_eq!(output1, output2); } +#[test] +fn test_output_conflict_options() { + for option in ["-i", "-T", "-P"] { + new_ucmd!().arg("--output=source").arg(option).fails(); + } +} + +#[test] +fn test_output_option() { + new_ucmd!().arg("--output").succeeds(); + new_ucmd!().arg("--output=source,target").succeeds(); + new_ucmd!().arg("--output=invalid_option").fails(); +} + +#[test] +fn test_type_option() { + new_ucmd!().args(&["-t", "ext4", "-t", "ext3"]).succeeds(); +} + // ToDO: more tests...