this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: allow compression levels 'none' 'fast' 'best'

+54 -17
+5 -7
src/bzip2.rs
··· 12 12 #[clap(flatten)] 13 13 pub common_args: CommonArgs, 14 14 15 - /// Level of compression. 16 - /// This is an int 0-9, with 0 being no compression and 9 being highest compression. 17 - #[arg(long, default_value_t = 6)] 18 - level: u32, 19 - // TODO: Support keywords none, fast, best 20 - // Correspond to 0, 1, 9 15 + #[clap(flatten)] 16 + pub level_args: LevelArgs, 21 17 } 22 18 23 19 pub struct Bzip2 { ··· 32 28 33 29 impl Bzip2 { 34 30 pub fn new(args: &Bzip2Args) -> Self { 35 - Bzip2 { level: args.level } 31 + Bzip2 { 32 + level: args.level_args.level.level, 33 + } 36 34 } 37 35 } 38 36
+3 -5
src/gzip.rs
··· 10 10 #[clap(flatten)] 11 11 pub common_args: CommonArgs, 12 12 13 - /// Level of compression. 14 - /// This is an int 0-9, with 0 being no compression and 9 being highest compression. 15 - #[arg(long, default_value_t = 6)] 16 - compression: u32, 13 + #[clap(flatten)] 14 + pub level_args: LevelArgs, 17 15 } 18 16 19 17 pub struct Gzip { ··· 31 29 impl Gzip { 32 30 pub fn new(args: &GzipArgs) -> Gzip { 33 31 Gzip { 34 - compression_level: args.compression, 32 + compression_level: args.level_args.level.level, 35 33 } 36 34 } 37 35 }
+43
src/utils.rs
··· 1 1 use clap::Args; 2 2 use std::io; 3 3 use std::path::{Path, PathBuf}; 4 + use std::str::FromStr; 4 5 5 6 #[derive(Args, Debug)] 6 7 pub struct CommonArgs { ··· 36 37 /// Ignore stdout when inferring I/O 37 38 #[arg(long)] 38 39 pub ignore_stdout: bool, 40 + } 41 + 42 + #[derive(Debug, Clone, Copy)] 43 + pub struct CompressionLevel { 44 + pub level: u32, 45 + } 46 + 47 + impl Default for CompressionLevel { 48 + fn default() -> Self { 49 + CompressionLevel { level: 6 } 50 + } 51 + } 52 + 53 + impl FromStr for CompressionLevel { 54 + type Err = &'static str; 55 + 56 + fn from_str(s: &str) -> Result<Self, Self::Err> { 57 + // Check for an int 58 + if let Ok(level) = s.parse::<u32>() { 59 + if level < 10 { 60 + return Ok(CompressionLevel { level }); 61 + } else { 62 + return Err("Compression level must be 0-9"); 63 + } 64 + } 65 + let s = s.to_lowercase(); 66 + match s.as_str() { 67 + "none" => Ok(CompressionLevel { level: 0 }), 68 + "fast" => Ok(CompressionLevel { level: 1 }), 69 + "best" => Ok(CompressionLevel { level: 9 }), 70 + _ => Err("Invalid compression level"), 71 + } 72 + } 73 + } 74 + 75 + #[derive(Args, Debug, Default, Clone, Copy)] 76 + pub struct LevelArgs { 77 + /// Level of compression. 78 + /// This is an int 0-9, with 0 being no compression and 9 being highest compression. 79 + /// Also supports 'none', 'fast', and 'best'. 80 + #[arg(long, default_value = "6")] 81 + pub level: CompressionLevel, 39 82 } 40 83 41 84 /// Common interface for all compressor implementations
+3 -5
src/xz.rs
··· 17 17 #[clap(flatten)] 18 18 progress_args: ProgressArgs, 19 19 20 - /// Level of compression. 21 - /// This is an int 0-9, with 0 being no compression and 9 being highest compression. 22 - #[arg(long, default_value_t = 6)] 23 - level: u32, 20 + #[clap(flatten)] 21 + pub level_args: LevelArgs, 24 22 } 25 23 26 24 pub struct Xz { ··· 40 38 impl Xz { 41 39 pub fn new(args: &XzArgs) -> Xz { 42 40 Xz { 43 - level: args.level, 41 + level: args.level_args.level.level, 44 42 progress_args: args.progress_args, 45 43 } 46 44 }