this repo has no description
0
fork

Configure Feed

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

fix: improve output identification

+23 -14
+23 -14
src/main.rs
··· 131 131 } 132 132 133 133 /// Parse the common args and determine the details of the job requested 134 - fn get_job(common_args: &CommonArgs) -> Result<Job, io::Error> { 134 + fn get_job<T: Compressor>(compressor: &T, common_args: &CommonArgs) -> Result<Job, io::Error> { 135 135 let action = { 136 136 if common_args.compress { 137 137 Action::Compress ··· 180 180 output = Some(path); 181 181 io_list.pop(); 182 182 } else if path.is_dir() { 183 - if std::io::stdout().is_terminal() { 184 - // stdout isn't a pipe, so use this directory as output 185 - output = Some(path); 186 - io_list.pop(); 187 - } else { 188 - // this is a directory and stdout is a pipe 189 - // TODO: This may need to ask the user, for now assume stdout is output 190 - } 183 + match action { 184 + Action::Compress => { 185 + // A directory can potentially be a target output location or 186 + // an input, for now assume it is an input. 187 + } 188 + Action::Extract => { 189 + // Can extract to a directory, and it wouldn't make any sense as an input 190 + output = Some(path); 191 + io_list.pop(); 192 + } 193 + }; 191 194 } else { 192 195 // TODO: append checks 193 196 } ··· 223 226 if !std::io::stdout().is_terminal() { 224 227 CmprssOutput::Pipe(std::io::stdout()) 225 228 } else { 226 - // TODO: add fallback checks 227 - // There are a number of combinations where we can't be sure 228 - println!("error: No valid output detected. This may be because the output file already exists."); 229 - return Err(io::Error::new(io::ErrorKind::Other, "No specified output")); 229 + match action { 230 + Action::Compress => { 231 + // Use a default filename 232 + CmprssOutput::Path(PathBuf::from( 233 + compressor.default_compressed_filename(Path::new("archive")), 234 + )) 235 + } 236 + Action::Extract => CmprssOutput::Path(PathBuf::from(".")), 237 + } 230 238 } 231 239 } 232 240 }; ··· 239 247 } 240 248 241 249 fn command<T: Compressor>(compressor: T, args: &CommonArgs) -> Result<(), io::Error> { 242 - let job = get_job(args)?; 250 + let job = get_job(&compressor, args)?; 243 251 252 + // TODO: Print expected actions, and ask for confirmation if there's ambiguity 244 253 match job.action { 245 254 Action::Compress => compressor.compress(job.input, job.output)?, 246 255 Action::Extract => compressor.extract(job.input, job.output)?,