this repo has no description
0
fork

Configure Feed

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

fix: use first file's name to generate output filename

+22 -36
+14 -29
src/main.rs
··· 87 87 compression: u32, 88 88 } 89 89 90 - /// Get the input filename or return an error 91 - fn get_input_filename(input: &Option<String>) -> Result<&String, io::Error> { 90 + /// Get the input filename or return a default file 91 + /// This file will be used to generate the output filename 92 + fn get_input_filename(input: &CmprssInput) -> Result<&Path, io::Error> { 92 93 match input { 93 - Some(filename) => Ok(filename), 94 - None => Err(io::Error::new( 95 - io::ErrorKind::Other, 96 - "error: no input specified", 97 - )), 98 - } 99 - } 100 - 101 - /// Get the default output filename or return error if the input isn't specified 102 - #[allow(dead_code)] 103 - fn get_default_output<T: Compressor>( 104 - compressor: &T, 105 - input: &Option<String>, 106 - extract: bool, 107 - ) -> Result<String, io::Error> { 108 - let filename = match get_input_filename(input) { 109 - Ok(name) => name, 110 - Err(_) => { 111 - return Err(io::Error::new( 112 - io::ErrorKind::Other, 113 - "error: can't infer output name while using stdin for input", 114 - )) 94 + CmprssInput::Path(paths) => { 95 + if paths.is_empty() { 96 + return Err(io::Error::new( 97 + io::ErrorKind::Other, 98 + "error: no input specified", 99 + )); 100 + } 101 + Ok(paths.first().unwrap()) 115 102 } 116 - }; 117 - match extract { 118 - true => Ok(compressor.default_extracted_filename(Path::new(filename))), 119 - false => Ok(compressor.default_compressed_filename(Path::new(filename))), 103 + CmprssInput::Pipe(_) => Ok(Path::new("archive")), 120 104 } 121 105 } 122 106 ··· 234 218 Action::Compress => { 235 219 // Use a default filename 236 220 CmprssOutput::Path(PathBuf::from( 237 - compressor.default_compressed_filename(Path::new("archive")), 221 + compressor 222 + .default_compressed_filename(get_input_filename(&cmprss_input)?), 238 223 )) 239 224 } 240 225 Action::Extract => CmprssOutput::Path(PathBuf::from(".")),
+8 -7
tests/cli.rs
··· 82 82 Ok(()) 83 83 } 84 84 85 - /// Tar roundtrip with a single file inferring output 86 - /// Compressing: output = './archive.tar' 85 + /// Tar roundtrip with a single file inferring output filename 86 + /// Compressing: output = './test.txt.tar' 87 87 /// Extracting: output = '.' 88 88 /// 89 89 /// ``` bash 90 90 /// cmprss tar test.txt 91 - /// cmprss tar --extract archive.tar 91 + /// cmprss tar --extract test.txt.tar 92 92 /// ``` 93 93 #[test] 94 94 fn tar_roundtrip_implicit() -> Result<(), Box<dyn std::error::Error>> { 95 95 let file = assert_fs::NamedTempFile::new("test.txt")?; 96 96 file.write_str("garbage data for testing")?; 97 97 let working_dir = assert_fs::TempDir::new()?.into_persistent(); 98 - let archive = working_dir.child("archive.tar"); 98 + let archive = working_dir.child("test.txt.tar"); 99 99 archive.assert(predicate::path::missing()); 100 100 101 101 let mut compress = Command::cargo_bin("cmprss")?; ··· 125 125 } 126 126 127 127 /// Tar roundtrip with multiple files inferring output 128 - /// Compressing: output = './archive.tar' 128 + /// Uses the first file's name to generate the output filename 129 + /// Compressing: output = './test.txt.tar' 129 130 /// Extracting: output = '.' 130 131 /// 131 132 /// ``` bash 132 133 /// cmprss tar test.txt test2.txt 133 - /// cmprss tar --extract archive.tar 134 + /// cmprss tar --extract test.txt.tar 134 135 /// ``` 135 136 #[test] 136 137 fn tar_roundtrip_implicit_two() -> Result<(), Box<dyn std::error::Error>> { ··· 139 140 let file2 = assert_fs::NamedTempFile::new("test2.txt")?; 140 141 file2.write_str("more garbage data for testing")?; 141 142 let working_dir = assert_fs::TempDir::new()?.into_persistent(); 142 - let archive = working_dir.child("archive.tar"); 143 + let archive = working_dir.child("test.txt.tar"); 143 144 archive.assert(predicate::path::missing()); 144 145 145 146 let mut compress = Command::cargo_bin("cmprss")?;