···131131}
132132133133/// Parse the common args and determine the details of the job requested
134134-fn get_job(common_args: &CommonArgs) -> Result<Job, io::Error> {
134134+fn get_job<T: Compressor>(compressor: &T, common_args: &CommonArgs) -> Result<Job, io::Error> {
135135 let action = {
136136 if common_args.compress {
137137 Action::Compress
···180180 output = Some(path);
181181 io_list.pop();
182182 } else if path.is_dir() {
183183- if std::io::stdout().is_terminal() {
184184- // stdout isn't a pipe, so use this directory as output
185185- output = Some(path);
186186- io_list.pop();
187187- } else {
188188- // this is a directory and stdout is a pipe
189189- // TODO: This may need to ask the user, for now assume stdout is output
190190- }
183183+ match action {
184184+ Action::Compress => {
185185+ // A directory can potentially be a target output location or
186186+ // an input, for now assume it is an input.
187187+ }
188188+ Action::Extract => {
189189+ // Can extract to a directory, and it wouldn't make any sense as an input
190190+ output = Some(path);
191191+ io_list.pop();
192192+ }
193193+ };
191194 } else {
192195 // TODO: append checks
193196 }
···223226 if !std::io::stdout().is_terminal() {
224227 CmprssOutput::Pipe(std::io::stdout())
225228 } else {
226226- // TODO: add fallback checks
227227- // There are a number of combinations where we can't be sure
228228- println!("error: No valid output detected. This may be because the output file already exists.");
229229- return Err(io::Error::new(io::ErrorKind::Other, "No specified output"));
229229+ match action {
230230+ Action::Compress => {
231231+ // Use a default filename
232232+ CmprssOutput::Path(PathBuf::from(
233233+ compressor.default_compressed_filename(Path::new("archive")),
234234+ ))
235235+ }
236236+ Action::Extract => CmprssOutput::Path(PathBuf::from(".")),
237237+ }
230238 }
231239 }
232240 };
···239247}
240248241249fn command<T: Compressor>(compressor: T, args: &CommonArgs) -> Result<(), io::Error> {
242242- let job = get_job(args)?;
250250+ let job = get_job(&compressor, args)?;
243251252252+ // TODO: Print expected actions, and ask for confirmation if there's ambiguity
244253 match job.action {
245254 Action::Compress => compressor.compress(job.input, job.output)?,
246255 Action::Extract => compressor.extract(job.input, job.output)?,