1
0
mirror of https://github.com/sharkdp/bat synced 2026-07-22 16:53:19 +00:00

Add *_with_name methods

This commit is contained in:
sharkdp
2020-04-22 22:41:25 +02:00
committed by David Peter
parent 53a973e9dd
commit 261a7ea154
5 changed files with 37 additions and 13 deletions
+3 -8
View File
@@ -246,8 +246,7 @@ impl App {
let files: Option<Vec<&OsStr>> = self.matches.values_of_os("FILE").map(|vs| vs.collect());
if files.is_none() {
let mut input = Input::stdin();
input.set_provided_name(filenames_or_none.nth(0).unwrap_or(None));
let input = Input::stdin().with_name(filenames_or_none.nth(0).unwrap_or(None));
return Ok(vec![input]);
}
let files_or_none: Box<dyn Iterator<Item = _>> = match files {
@@ -259,13 +258,9 @@ impl App {
for (filepath, provided_name) in files_or_none.zip(filenames_or_none) {
if let Some(filepath) = filepath {
if filepath.to_str().unwrap_or_default() == "-" {
let mut input = Input::stdin();
input.set_provided_name(provided_name);
file_input.push(input);
file_input.push(Input::stdin().with_name(provided_name));
} else {
let mut input = Input::ordinary_file(filepath);
input.set_provided_name(provided_name);
file_input.push(input);
file_input.push(Input::ordinary_file(filepath).with_name(provided_name));
}
}
}