mirror of
https://github.com/sharkdp/bat.git
synced 2024-11-23 00:03:27 +01:00
Minor --file-name code hygeine
This commit is contained in:
parent
131d113ff5
commit
83772bd2cf
@ -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 {
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user