this repo has no description
0
fork

Configure Feed

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

refactor: running auto-fixers

+84 -87
+1
flake.nix
··· 233 233 nodePackages.prettier 234 234 shellcheck 235 235 statix 236 + typos 236 237 237 238 # For running tests 238 239 diffutils
+6 -6
src/backends/gzip.rs
··· 67 67 68 68 /// Compress an input file or pipe to a gzip archive 69 69 fn compress(&self, input: CmprssInput, output: CmprssOutput) -> Result { 70 - if let CmprssOutput::Path(out_path) = &output { 71 - if out_path.is_dir() { 72 - bail!( 73 - "Gzip does not support compressing to a directory. Please specify an output file." 74 - ); 75 - } 70 + if let CmprssOutput::Path(out_path) = &output 71 + && out_path.is_dir() 72 + { 73 + bail!( 74 + "Gzip does not support compressing to a directory. Please specify an output file." 75 + ); 76 76 } 77 77 if let CmprssInput::Path(input_paths) = &input { 78 78 for x in input_paths {
+10 -12
src/backends/lz4.rs
··· 41 41 42 42 /// Compress an input file or pipe to a lz4 archive 43 43 fn compress(&self, input: CmprssInput, output: CmprssOutput) -> Result { 44 - if let CmprssOutput::Path(out_path) = &output { 45 - if out_path.is_dir() { 46 - bail!( 47 - "LZ4 does not support compressing to a directory. Please specify an output file." 48 - ); 49 - } 44 + if let CmprssOutput::Path(out_path) = &output 45 + && out_path.is_dir() 46 + { 47 + bail!( 48 + "LZ4 does not support compressing to a directory. Please specify an output file." 49 + ); 50 50 } 51 51 if let CmprssInput::Path(input_paths) = &input { 52 52 for x in input_paths { ··· 98 98 99 99 /// Extract a lz4 archive to an output file or pipe 100 100 fn extract(&self, input: CmprssInput, output: CmprssOutput) -> Result { 101 - if let CmprssOutput::Path(out_path) = &output { 102 - if out_path.is_dir() { 103 - bail!( 104 - "LZ4 does not support extracting to a directory. Please specify an output file." 105 - ); 106 - } 101 + if let CmprssOutput::Path(out_path) = &output 102 + && out_path.is_dir() 103 + { 104 + bail!("LZ4 does not support extracting to a directory. Please specify an output file."); 107 105 } 108 106 109 107 let mut file_size = None;
+12 -12
src/backends/zstd.rs
··· 86 86 87 87 /// Compress an input file or pipe to a zstd archive 88 88 fn compress(&self, input: CmprssInput, output: CmprssOutput) -> Result { 89 - if let CmprssOutput::Path(out_path) = &output { 90 - if out_path.is_dir() { 91 - bail!( 92 - "Zstd does not support compressing to a directory. Please specify an output file." 93 - ); 94 - } 89 + if let CmprssOutput::Path(out_path) = &output 90 + && out_path.is_dir() 91 + { 92 + bail!( 93 + "Zstd does not support compressing to a directory. Please specify an output file." 94 + ); 95 95 } 96 96 if let CmprssInput::Path(input_paths) = &input { 97 97 for x in input_paths { ··· 143 143 144 144 /// Extract a zstd archive to an output file or pipe 145 145 fn extract(&self, input: CmprssInput, output: CmprssOutput) -> Result { 146 - if let CmprssOutput::Path(out_path) = &output { 147 - if out_path.is_dir() { 148 - bail!( 149 - "Zstd does not support extracting to a directory. Please specify an output file." 150 - ); 151 - } 146 + if let CmprssOutput::Path(out_path) = &output 147 + && out_path.is_dir() 148 + { 149 + bail!( 150 + "Zstd does not support extracting to a directory. Please specify an output file." 151 + ); 152 152 } 153 153 154 154 let mut file_size = None;
+49 -49
src/main.rs
··· 134 134 // Check if output is a directory - this is likely an extraction 135 135 if output.is_dir() { 136 136 // Try to determine compressor from the input file's extension(s) 137 - if let Some(input_path) = input.first() { 138 - if let Some(guessed_compressor) = get_compressor_from_filename(input_path) { 139 - return (Some(guessed_compressor), Action::Extract); 140 - } 137 + if let Some(input_path) = input.first() 138 + && let Some(guessed_compressor) = get_compressor_from_filename(input_path) 139 + { 140 + return (Some(guessed_compressor), Action::Extract); 141 141 } 142 142 } 143 143 ··· 247 247 248 248 // Process the io_list, check if there is an output first 249 249 let mut io_list = common_args.io_list.clone(); 250 - if output.is_none() { 251 - if let Some(possible_output) = common_args.io_list.last() { 252 - let path = Path::new(possible_output); 253 - if !path.try_exists()? { 254 - // Use the given path if it doesn't exist 255 - output = Some(path); 256 - io_list.pop(); 257 - } else if path.is_dir() { 258 - match action { 259 - Action::Compress => { 260 - // A directory can potentially be a target output location or 261 - // an input, for now assume it is an input. 262 - } 263 - Action::Extract => { 264 - // Can extract to a directory, and it wouldn't make any sense as an input 265 - output = Some(path); 266 - io_list.pop(); 267 - } 268 - _ => { 269 - // TODO: don't know if this is an input or output, assume we're compressing this directory 270 - // This does cause problems for inferencing "cat archive.tar | cmprss tar ." 271 - // Probably need to add some special casing 272 - } 273 - }; 274 - } else { 275 - // TODO: check for scenarios where we want to append to an existing archive 276 - } 250 + if output.is_none() 251 + && let Some(possible_output) = common_args.io_list.last() 252 + { 253 + let path = Path::new(possible_output); 254 + if !path.try_exists()? { 255 + // Use the given path if it doesn't exist 256 + output = Some(path); 257 + io_list.pop(); 258 + } else if path.is_dir() { 259 + match action { 260 + Action::Compress => { 261 + // A directory can potentially be a target output location or 262 + // an input, for now assume it is an input. 263 + } 264 + Action::Extract => { 265 + // Can extract to a directory, and it wouldn't make any sense as an input 266 + output = Some(path); 267 + io_list.pop(); 268 + } 269 + _ => { 270 + // TODO: don't know if this is an input or output, assume we're compressing this directory 271 + // This does cause problems for inferencing "cat archive.tar | cmprss tar ." 272 + // Probably need to add some special casing 273 + } 274 + }; 275 + } else { 276 + // TODO: check for scenarios where we want to append to an existing archive 277 277 } 278 278 } 279 279 ··· 498 498 Ok(()) 499 499 } 500 500 501 + fn main() { 502 + let args = CmprssArgs::parse(); 503 + match args.format { 504 + Some(Format::Tar(a)) => command(Some(Box::new(Tar::new(&a))), &a.common_args), 505 + Some(Format::Gzip(a)) => command(Some(Box::new(Gzip::new(&a))), &a.common_args), 506 + Some(Format::Xz(a)) => command(Some(Box::new(Xz::new(&a))), &a.common_args), 507 + Some(Format::Bzip2(a)) => command(Some(Box::new(Bzip2::new(&a))), &a.common_args), 508 + Some(Format::Zip(a)) => command(Some(Box::new(Zip::new(&a))), &a.common_args), 509 + Some(Format::Zstd(a)) => command(Some(Box::new(Zstd::new(&a))), &a.common_args), 510 + Some(Format::Lz4(a)) => command(Some(Box::new(Lz4::new(&a))), &a.common_args), 511 + _ => command(None, &args.base_args), 512 + } 513 + .unwrap_or_else(|e| { 514 + eprintln!("ERROR(cmprss): {}", e); 515 + std::process::exit(1); 516 + }); 517 + } 518 + 501 519 #[cfg(test)] 502 520 mod tests { 503 521 use super::*; ··· 601 619 assert_eq!(compressor_extension("file.tar"), Some("tar".into())); 602 620 } 603 621 } 604 - 605 - fn main() { 606 - let args = CmprssArgs::parse(); 607 - match args.format { 608 - Some(Format::Tar(a)) => command(Some(Box::new(Tar::new(&a))), &a.common_args), 609 - Some(Format::Gzip(a)) => command(Some(Box::new(Gzip::new(&a))), &a.common_args), 610 - Some(Format::Xz(a)) => command(Some(Box::new(Xz::new(&a))), &a.common_args), 611 - Some(Format::Bzip2(a)) => command(Some(Box::new(Bzip2::new(&a))), &a.common_args), 612 - Some(Format::Zip(a)) => command(Some(Box::new(Zip::new(&a))), &a.common_args), 613 - Some(Format::Zstd(a)) => command(Some(Box::new(Zstd::new(&a))), &a.common_args), 614 - Some(Format::Lz4(a)) => command(Some(Box::new(Lz4::new(&a))), &a.common_args), 615 - _ => command(None, &args.base_args), 616 - } 617 - .unwrap_or_else(|e| { 618 - eprintln!("ERROR(cmprss): {}", e); 619 - std::process::exit(1); 620 - }); 621 - }
+6 -8
src/utils.rs
··· 205 205 // If the file has no extension, return the current directory 206 206 if let Some(ext) = in_path.extension() { 207 207 // If the file has the extension for this type, return the filename without the extension 208 - if let Some(ext_str) = ext.to_str() { 209 - if ext_str == self.extension() { 210 - if let Some(stem) = in_path.file_stem() { 211 - if let Some(stem_str) = stem.to_str() { 212 - return stem_str.to_string(); 213 - } 214 - } 215 - } 208 + if let Some(ext_str) = ext.to_str() 209 + && ext_str == self.extension() 210 + && let Some(stem) = in_path.file_stem() 211 + && let Some(stem_str) = stem.to_str() 212 + { 213 + return stem_str.to_string(); 216 214 } 217 215 } 218 216 "archive".to_string()