this repo has no description
0
fork

Configure Feed

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

refactor(clap): use common arguments struct

+23 -21
+23 -21
src/main.rs
··· 42 42 43 43 #[derive(Args, Debug)] 44 44 struct TarArgs { 45 + #[clap(flatten)] 46 + common_args: CommonArgs, 47 + } 48 + 49 + #[derive(Args, Debug)] 50 + struct CommonArgs { 45 51 /// Input file 46 52 #[arg(index = 1)] 47 53 input: String, ··· 59 65 extract: bool, 60 66 } 61 67 68 + impl CommonArgs { 69 + /// Convert clap argument struct into utils::CmprssCommonArgs 70 + /// This is done, perhaps unnecessarily, to keep clap out of the lib 71 + fn into_common(self) -> CmprssCommonArgs { 72 + CmprssCommonArgs { 73 + compress: self.compress, 74 + input: self.input, 75 + output: self.output, 76 + extract: self.extract, 77 + } 78 + } 79 + } 80 + 62 81 #[derive(Args, Debug)] 63 82 struct GzipArgs { 64 - /// Input file 65 - #[arg(index = 1)] 66 - input: String, 67 - 68 - /// Output file/directory 69 - #[arg(index = 2)] 70 - output: Option<String>, 71 - 72 - /// Compress the input (default) 73 - #[arg(short, long)] 74 - compress: bool, 75 - 76 - /// Extract the input 77 - #[arg(short, long)] 78 - extract: bool, 83 + #[clap(flatten)] 84 + common_args: CommonArgs, 79 85 80 86 /// Level of compression 81 87 /// ··· 101 107 102 108 /// Execute a tar command 103 109 fn command_tar(args: TarArgs) { 110 + let args = args.common_args; 104 111 let input_path = Path::new(&args.input); 105 112 if args.compress { 106 113 let out = output_filename(input_path, &args.output, tar::EXT); ··· 162 169 fn parse_gzip(args: GzipArgs) -> gzip::Gzip { 163 170 gzip::Gzip { 164 171 compression_level: args.compression, 165 - common_args: CmprssCommonArgs { 166 - compress: args.compress, 167 - extract: args.extract, 168 - input: args.input, 169 - output: args.output, 170 - }, 172 + common_args: args.common_args.into_common(), 171 173 } 172 174 } 173 175