this repo has no description
0
fork

Configure Feed

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

feat(cli): preserve shortcut format string in default output name

+52 -2
+23 -1
src/backends/pipeline.rs
··· 11 11 pub struct Pipeline { 12 12 // The chain of compressors to apply in order (innermost to outermost) 13 13 compressors: Vec<Box<dyn Compressor>>, 14 + /// Preserves the user's original format string (e.g. `tgz`) so default 15 + /// filenames use it verbatim instead of the dotted composition of each 16 + /// stage's extension. `None` falls back to joining the per-stage 17 + /// extensions. 18 + format_override: Option<String>, 14 19 } 15 20 16 21 impl Clone for Pipeline { 17 22 fn clone(&self) -> Self { 18 23 Pipeline { 19 24 compressors: self.compressors.iter().map(|c| c.clone_boxed()).collect(), 25 + format_override: self.format_override.clone(), 20 26 } 21 27 } 22 28 } ··· 33 39 impl Pipeline { 34 40 /// Create a new Pipeline with the given compressors 35 41 pub fn new(compressors: Vec<Box<dyn Compressor>>) -> Self { 36 - Pipeline { compressors } 42 + Pipeline { 43 + compressors, 44 + format_override: None, 45 + } 46 + } 47 + 48 + /// Create a Pipeline that keeps `format` as its canonical format string, 49 + /// used for default output filenames. Intended for shortcut forms like 50 + /// `tgz` where the user-facing extension differs from the dotted chain. 51 + pub fn with_format(compressors: Vec<Box<dyn Compressor>>, format: String) -> Self { 52 + Pipeline { 53 + compressors, 54 + format_override: Some(format), 55 + } 37 56 } 38 57 39 58 /// Get a string representation of the chained format (e.g., "tar.gz") 40 59 fn format_chain(&self) -> String { 60 + if let Some(ref f) = self.format_override { 61 + return f.clone(); 62 + } 41 63 self.compressors 42 64 .iter() 43 65 .map(|c| c.extension())
+2 -1
src/main.rs
··· 89 89 return None; 90 90 } 91 91 let chain = chain_from_format_str(first)?; 92 + let format = first.clone(); 92 93 io_list.remove(0); 93 - Some(Box::new(Pipeline::new(chain))) 94 + Some(Box::new(Pipeline::with_format(chain, format))) 94 95 } 95 96 96 97 fn write_completions(shell: Shell) -> Result {
+27
tests/shortcuts.rs
··· 113 113 mod format_prefix { 114 114 use super::*; 115 115 116 + /// When the user explicitly names a shortcut format like `tgz`, the 117 + /// inferred output filename should keep that spelling instead of the 118 + /// expanded `.tar.gz` form. 119 + #[test] 120 + fn shortcut_preserves_extension_in_default_name() -> Result<(), Box<dyn std::error::Error>> { 121 + let working_dir = create_working_dir()?; 122 + let src = working_dir.child("payload"); 123 + src.create_dir_all()?; 124 + src.child("a.txt").write_str("hello")?; 125 + 126 + let mut compress = Command::cargo_bin("cmprss")?; 127 + compress 128 + .current_dir(&working_dir) 129 + .arg("--ignore-pipes") 130 + .arg("tgz") 131 + .arg("payload"); 132 + compress.assert().success(); 133 + 134 + working_dir 135 + .child("payload.tgz") 136 + .assert(predicate::path::is_file()); 137 + working_dir 138 + .child("payload.tar.gz") 139 + .assert(predicate::path::missing()); 140 + Ok(()) 141 + } 142 + 116 143 #[test] 117 144 fn tar_gz() -> Result<(), Box<dyn std::error::Error>> { 118 145 format_prefix_roundtrip("tar.gz", "tar.gz")