Use clap conflict argument checks (#219)
Follow-up to #210. I haven't noticed / forgotten that clap has own mechanism for conflicts between arguments, and it's probably best to use it instead of custom checks.
This commit is contained in:
parent
a497513d89
commit
3b754bfa09
1 changed files with 12 additions and 21 deletions
33
src/main.rs
33
src/main.rs
|
|
@ -147,7 +147,8 @@ fn main() {
|
||||||
Ok(_) => Ok(()),
|
Ok(_) => Ok(()),
|
||||||
Err(_) => Err("Invalid option for compression".to_owned()),
|
Err(_) => Err("Invalid option for compression".to_owned()),
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
|
.conflicts_with_all(&["zopfli", "libdeflater"]))
|
||||||
.arg(Arg::with_name("strategies")
|
.arg(Arg::with_name("strategies")
|
||||||
.help("zlib compression strategies (0-3) - Default: 0-3")
|
.help("zlib compression strategies (0-3) - Default: 0-3")
|
||||||
.long("zs")
|
.long("zs")
|
||||||
|
|
@ -157,7 +158,8 @@ fn main() {
|
||||||
Ok(_) => Ok(()),
|
Ok(_) => Ok(()),
|
||||||
Err(_) => Err("Invalid option for strategies".to_owned()),
|
Err(_) => Err("Invalid option for strategies".to_owned()),
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
|
.conflicts_with_all(&["zopfli", "libdeflater"]))
|
||||||
.arg(Arg::with_name("window")
|
.arg(Arg::with_name("window")
|
||||||
.help("zlib window size - Default: 32k")
|
.help("zlib window size - Default: 32k")
|
||||||
.long("zw")
|
.long("zw")
|
||||||
|
|
@ -170,7 +172,8 @@ fn main() {
|
||||||
.possible_value("4k")
|
.possible_value("4k")
|
||||||
.possible_value("8k")
|
.possible_value("8k")
|
||||||
.possible_value("16k")
|
.possible_value("16k")
|
||||||
.possible_value("32k"))
|
.possible_value("32k")
|
||||||
|
.conflicts_with_all(&["zopfli", "libdeflater"]))
|
||||||
.arg(Arg::with_name("no-bit-reduction")
|
.arg(Arg::with_name("no-bit-reduction")
|
||||||
.help("No bit depth reduction")
|
.help("No bit depth reduction")
|
||||||
.long("nb"))
|
.long("nb"))
|
||||||
|
|
@ -192,11 +195,13 @@ fn main() {
|
||||||
.arg(Arg::with_name("zopfli")
|
.arg(Arg::with_name("zopfli")
|
||||||
.help("Use the slower but better compressing Zopfli algorithm, overrides zlib-specific options")
|
.help("Use the slower but better compressing Zopfli algorithm, overrides zlib-specific options")
|
||||||
.short("Z")
|
.short("Z")
|
||||||
.long("zopfli"))
|
.long("zopfli")
|
||||||
|
.conflicts_with("libdeflater"))
|
||||||
.arg(Arg::with_name("libdeflater")
|
.arg(Arg::with_name("libdeflater")
|
||||||
.help("Use an alternative Libdeflater algorithm, overrides zlib-specific options")
|
.help("Use an alternative Libdeflater algorithm, overrides zlib-specific options")
|
||||||
.short("D")
|
.short("D")
|
||||||
.long("libdeflater"))
|
.long("libdeflater")
|
||||||
|
.conflicts_with("zopfli"))
|
||||||
.arg(Arg::with_name("timeout")
|
.arg(Arg::with_name("timeout")
|
||||||
.help("Maximum amount of time, in seconds, to spend on optimizations")
|
.help("Maximum amount of time, in seconds, to spend on optimizations")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
|
|
@ -459,16 +464,9 @@ fn parse_opts_into_struct(
|
||||||
|
|
||||||
if matches.is_present("zopfli") {
|
if matches.is_present("zopfli") {
|
||||||
opts.deflate = Deflaters::Zopfli;
|
opts.deflate = Deflaters::Zopfli;
|
||||||
}
|
} else if matches.is_present("libdeflater") {
|
||||||
|
|
||||||
if matches.is_present("libdeflater") {
|
|
||||||
if matches.is_present("zopfli") {
|
|
||||||
return Err("zopfli and libdeflater can't be used simultaneously".to_owned());
|
|
||||||
}
|
|
||||||
opts.deflate = Deflaters::Libdeflater;
|
opts.deflate = Deflaters::Libdeflater;
|
||||||
}
|
} else if let Deflaters::Zlib {
|
||||||
|
|
||||||
if let Deflaters::Zlib {
|
|
||||||
compression,
|
compression,
|
||||||
strategies,
|
strategies,
|
||||||
window,
|
window,
|
||||||
|
|
@ -493,13 +491,6 @@ fn parse_opts_into_struct(
|
||||||
// 32k is default
|
// 32k is default
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
} else if matches.is_present("compression")
|
|
||||||
|| matches.is_present("strategies")
|
|
||||||
|| matches.is_present("window")
|
|
||||||
{
|
|
||||||
return Err(
|
|
||||||
"compression, strategies and window options are compatible only with zlib".to_owned(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(x) = matches.value_of("threads") {
|
if let Some(x) = matches.value_of("threads") {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue