diff --git a/CHANGELOG.md b/CHANGELOG.md index 032c17bf7..ba185a82b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,12 @@ Categories Used: ## [Unreleased](https://github.com/ouch-org/ouch/compare/0.4.1...HEAD) +### New Features + +- Add flags to configure the compression level + - `--level` to precisely set the compression level [\#372](https://github.com/ouch-org/ouch/pull/372) ([xgdgsc](https://github.com/xgdgsc)) + - `--fast` and `--slow` [\#374](https://github.com/ouch-org/ouch/pull/374) ([figsoda](https://github.com/figsoda)) + ### Improvements - Multi-threaded compression for gzip and snappy using gzp [\#348](https://github.com/ouch-org/ouch/pull/348) ([figsoda](https://github.com/figsoda)) diff --git a/src/cli/args.rs b/src/cli/args.rs index 1de90beff..266432fab 100644 --- a/src/cli/args.rs +++ b/src/cli/args.rs @@ -61,8 +61,18 @@ pub enum Subcommand { output: PathBuf, /// Compression level, applied to all formats - #[arg(short, long)] + #[arg(short, long, group = "compression-level")] level: Option, + + /// Fastest compression level possible, + /// conflicts with --level and --slow + #[arg(long, group = "compression-level")] + fast: bool, + + /// Slowest (and best) compression level possible, + /// conflicts with --level and --fast + #[arg(long, group = "compression-level")] + slow: bool, }, /// Decompresses one or more files, optionally into another folder #[command(visible_alias = "d")] diff --git a/src/commands/mod.rs b/src/commands/mod.rs index a4a3c8239..2d741406c 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -45,6 +45,8 @@ pub fn run( files, output: output_path, level, + fast, + slow, } => { // After cleaning, if there are no input files left, exit if files.is_empty() { @@ -73,6 +75,14 @@ pub fn run( None => return Ok(()), }; + let level = if fast { + Some(1) // Lowest level of compression + } else if slow { + Some(i16::MAX) // Highest level of compression + } else { + level + }; + let compress_result = compress_files( files, formats,