mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 19:47:45 +00:00
Args override themselves and conflicting arguments
This commit is contained in:
parent
85d113ab79
commit
c9bf31f97e
2 changed files with 52 additions and 7 deletions
|
@ -349,6 +349,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) {
|
||||
|
@ -422,6 +423,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(
|
||||
|
@ -429,47 +431,56 @@ 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",
|
||||
'-BM' prints sizes in units of 1,048,576 bytes",
|
||||
),
|
||||
)
|
||||
.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")
|
||||
.overrides_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")
|
||||
.overrides_with(OPT_HUMAN_READABLE_DECIMAL)
|
||||
.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(
|
||||
|
@ -493,12 +504,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(
|
||||
|
@ -514,6 +526,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(
|
||||
|
|
|
@ -27,9 +27,41 @@ fn test_df_compatible_si() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_df_overriding() {
|
||||
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]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue