this repo has no description
0
fork

Configure Feed

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

feat: add flags to ignore just stdin or stdout pipes

+56 -3
+16 -2
src/main.rs
··· 73 73 /// Ignore pipes when inferring I/O 74 74 #[arg(long)] 75 75 ignore_pipes: bool, 76 + 77 + /// Ignore stdin when inferring I/O 78 + #[arg(long)] 79 + ignore_stdin: bool, 80 + 81 + /// Ignore stdout when inferring I/O 82 + #[arg(long)] 83 + ignore_stdout: bool, 76 84 } 77 85 78 86 #[derive(Args, Debug)] ··· 200 208 // Fallback to stdin/stdout if we're missing files 201 209 let cmprss_input = match inputs.is_empty() { 202 210 true => { 203 - if !std::io::stdin().is_terminal() && !&common_args.ignore_pipes { 211 + if !std::io::stdin().is_terminal() 212 + && !&common_args.ignore_pipes 213 + && !&common_args.ignore_stdin 214 + { 204 215 CmprssInput::Pipe(std::io::stdin()) 205 216 } else { 206 217 return Err(io::Error::new(io::ErrorKind::Other, "No specified input")); ··· 211 222 let cmprss_output = match output { 212 223 Some(path) => CmprssOutput::Path(path.to_path_buf()), 213 224 None => { 214 - if !std::io::stdout().is_terminal() && !&common_args.ignore_pipes { 225 + if !std::io::stdout().is_terminal() 226 + && !&common_args.ignore_pipes 227 + && !&common_args.ignore_stdout 228 + { 215 229 CmprssOutput::Pipe(std::io::stdout()) 216 230 } else { 217 231 match action {
+40 -1
tests/cli.rs
··· 194 194 .arg("gzip") 195 195 .arg("--compression") 196 196 .arg("0") 197 - // TODO: add a flag to ignore just stdout so we can test each side 198 197 .arg("test.txt.gz") 199 198 .stdin(Stdio::from(File::open(file.path())?)); 200 199 compress.assert().success(); ··· 216 215 217 216 Ok(()) 218 217 } 218 + 219 + /// Gzip roundtrip using filename inference 220 + /// Compressing: input = stdin, output = default filename (archive.gz) 221 + /// Extracting: input = archive.gz, output = default filename (archive) 222 + #[test] 223 + fn gzip_roundtrip_inferred_output_filenames() -> Result<(), Box<dyn std::error::Error>> { 224 + let file = assert_fs::NamedTempFile::new("test.txt")?; 225 + file.write_str("garbage data for testing")?; 226 + let working_dir = assert_fs::TempDir::new()?; 227 + let archive = working_dir.child("archive.gz"); // default filename 228 + archive.assert(predicate::path::missing()); 229 + 230 + // Pipe file to stdin 231 + let mut compress = Command::cargo_bin("cmprss")?; 232 + compress 233 + .current_dir(&working_dir) 234 + .arg("gzip") 235 + .arg("--compression") 236 + .arg("0") 237 + .arg("--ignore-stdout") 238 + .stdin(Stdio::from(File::open(file.path())?)); 239 + compress.assert().success(); 240 + archive.assert(predicate::path::is_file()); 241 + 242 + let mut extract = Command::cargo_bin("cmprss")?; 243 + extract 244 + .current_dir(&working_dir) 245 + .arg("gzip") 246 + .arg("--ignore-pipes") 247 + .arg("--extract") 248 + .arg(archive.path()); 249 + extract.assert().success(); 250 + 251 + // Assert the files are identical 252 + working_dir 253 + .child("archive") 254 + .assert(predicate::path::eq_file(file.path())); 255 + 256 + Ok(()) 257 + }