mirror of
https://github.com/sharkdp/bat.git
synced 2025-01-31 10:11:07 +00: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()
|
match self.matches.values_of("file-name") {
|
||||||
&& self.matches.values_of("file-name").unwrap().len() != files.len()
|
Some(filenames) if filenames.len() != files.len() => {
|
||||||
{
|
return Err(format!("{} {}", filenames.len(), files.len()).into());
|
||||||
return Err("When using --file-name, each input file must have a corresponding --file-name specified.".into());
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Config {
|
Ok(Config {
|
||||||
|
@ -45,20 +45,12 @@ impl<'b> Controller<'b> {
|
|||||||
|
|
||||||
let stdin = io::stdin();
|
let stdin = io::stdin();
|
||||||
|
|
||||||
let filenames = if self.config.filenames.is_none() {
|
let filenames: Box<dyn Iterator<Item = _>> = match self.config.filenames {
|
||||||
vec![None; self.config.files.len()]
|
Some(ref filenames) => Box::new(filenames.into_iter().map(|name| Some(*name))),
|
||||||
} else {
|
None => Box::new(std::iter::repeat(None)),
|
||||||
self.config
|
|
||||||
.filenames
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.into_iter()
|
|
||||||
.map(|name| Some(*name))
|
|
||||||
.collect()
|
|
||||||
};
|
};
|
||||||
|
|
||||||
for it in self.config.files.iter().zip(filenames) {
|
for (input_file, file_name) in self.config.files.iter().zip(filenames) {
|
||||||
let (input_file, file_name) = it;
|
|
||||||
match input_file.get_reader(&stdin) {
|
match input_file.get_reader(&stdin) {
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
handle_error(&error);
|
handle_error(&error);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user