Minor --file-name code hygeine

This commit is contained in:
Kyle Criddle 2020-03-25 18:58:05 -06:00
parent 131d113ff5
commit 83772bd2cf
2 changed files with 9 additions and 16 deletions

View File

@ -136,10 +136,11 @@ impl App {
}
});
if self.matches.value_of("file-name").is_some()
&& self.matches.values_of("file-name").unwrap().len() != files.len()
{
return Err("When using --file-name, each input file must have a corresponding --file-name specified.".into());
match self.matches.values_of("file-name") {
Some(filenames) if filenames.len() != files.len() => {
return Err(format!("{} {}", filenames.len(), files.len()).into());
}
_ => {}
}
Ok(Config {

View File

@ -45,20 +45,12 @@ impl<'b> Controller<'b> {
let stdin = io::stdin();
let filenames = if self.config.filenames.is_none() {
vec![None; self.config.files.len()]
} else {
self.config
.filenames
.as_ref()
.unwrap()
.into_iter()
.map(|name| Some(*name))
.collect()
let filenames: Box<dyn Iterator<Item = _>> = match self.config.filenames {
Some(ref filenames) => Box::new(filenames.into_iter().map(|name| Some(*name))),
None => Box::new(std::iter::repeat(None)),
};
for it in self.config.files.iter().zip(filenames) {
let (input_file, file_name) = it;
for (input_file, file_name) in self.config.files.iter().zip(filenames) {
match input_file.get_reader(&stdin) {
Err(error) => {
handle_error(&error);