From 5536e5acd2b5cb3619c07e6c80994b19dca27a9c Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Mon, 20 Apr 2020 12:29:43 +0100 Subject: [PATCH] Add "max" level alias; more level warnings --- src/lib.rs | 10 +++++++++- src/main.rs | 32 ++++++++++++++++++-------------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 54500eb8..c5815fac 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -206,10 +206,18 @@ impl Options { opts.apply_preset_4() } 5 => opts.apply_preset_5(), - _ => opts.apply_preset_6(), + 6 => opts.apply_preset_6(), + _ => { + warn!("Level 7 and above don't exist yet and are identical to level 6"); + opts.apply_preset_6() + } } } + pub fn max_compression() -> Options { + Options::from_preset(6) + } + // The following methods make assumptions that they are operating // on an `Options` struct generated by the `default` method. fn apply_preset_0(mut self) -> Self { diff --git a/src/main.rs b/src/main.rs index aba4856c..999706de 100644 --- a/src/main.rs +++ b/src/main.rs @@ -52,7 +52,8 @@ fn main() { .possible_value("3") .possible_value("4") .possible_value("5") - .possible_value("6")) + .possible_value("6") + .possible_value("max")) .arg(Arg::with_name("backup") .help("Back up modified files") .short("b") @@ -227,13 +228,14 @@ fn main() { } })) .after_help("Optimization levels: - -o 0 => --zc 3 --nz (0 or 1 trials) - -o 1 => --zc 9 (1 trial, determined heuristically) - -o 2 => --zc 9 --zs 0-3 -f 0,5 (8 trials) - -o 3 => --zc 9 --zs 0-3 -f 0-5 (24 trials) - -o 4 => (deprecated; same as `-o 3`) - -o 5 => --zc 3-9 --zs 0-3 -f 0-5 (96 trials) - -o 6 => --zc 1-9 --zs 0-3 -f 0-5 (180 trials) + -o 0 => --zc 3 --nz (0 or 1 trials) + -o 1 => --zc 9 (1 trial, determined heuristically) + -o 2 => --zc 9 --zs 0-3 -f 0,5 (8 trials) + -o 3 => --zc 9 --zs 0-3 -f 0-5 (24 trials) + -o 4 => (deprecated; same as `-o 3`) + -o 5 => --zc 3-9 --zs 0-3 -f 0-5 (96 trials) + -o 6 => --zc 1-9 --zs 0-3 -f 0-5 (180 trials) + -o max => (alias for the max compression, currently same as -o 6) Manually specifying a compression option (zc, zs, etc.) will override the optimization preset, regardless of the order you write the arguments.") @@ -321,13 +323,15 @@ fn parse_opts_into_struct( .init() .unwrap(); - let level = match matches.value_of("optimization") { - Some(x) => x.parse::().unwrap(), - None => 2, + let (explicit_level, mut opts) = match matches.value_of("optimization") { + None => (None, Options::default()), + Some("max") => (None, Options::max_compression()), + Some(level) => { + let level = level.parse::().unwrap(); + (Some(level), Options::from_preset(level)) + } }; - let mut opts = Options::from_preset(level); - if let Some(x) = matches.value_of("interlace") { opts.interlace = x.parse::().ok(); } @@ -491,7 +495,7 @@ fn parse_opts_into_struct( } } - if level > 3 { + if explicit_level > Some(3) { match opts.deflate { Deflaters::Zlib { .. } => {} _ => {