on master help sign in
Remove Input.as_file and add Input::stdin_as_file
commit7a9decad709c5bee97f682e1641740f33b2d0a36 authorEthan P <eth-p+git@hidden.email> dateWed 27 May 2020, 15:40 (6 years ago) parentc4d0d06
2 files changed+14−8
src/bin/bat/app.rs+3−3 src/input.rs+11−5
src/bin/bat/app.rs+3−3
@@ -257,7 +257,7 @@ impl App {
257257 let files: Option<Vec<&OsStr>> = self.matches.values_of_os("FILE").map(|vs| vs.collect());
258258
259259 if files.is_none() {
260− let input = Input::stdin().as_file(filenames_or_none.next().unwrap_or(None));
260+ let input = Input::stdin_as_file(filenames_or_none.next().unwrap_or(None));
261261 return Ok(vec![input]);
262262 }
263263 let files_or_none: Box<dyn Iterator<Item = _>> = match files {
@@ -269,9 +269,9 @@ impl App {
269269 for (filepath, provided_name) in files_or_none.zip(filenames_or_none) {
270270 if let Some(filepath) = filepath {
271271 if filepath.to_str().unwrap_or_default() == "-" {
272− file_input.push(Input::stdin().as_file(provided_name));
272+ file_input.push(Input::stdin_as_file(provided_name));
273273 } else {
274− file_input.push(Input::ordinary_file(filepath).as_file(provided_name));
274+ file_input.push(Input::ordinary_file(filepath).with_name(provided_name));
275275 }
276276 }
277277 }
src/input.rs+11−5
@@ -125,6 +125,17 @@ impl<'a> Input<'a> {
125125 }
126126 }
127127
128+ pub fn stdin_as_file(name: Option<impl AsRef<OsStr>>) -> Self {
129+ match name {
130+ None => Input::stdin(),
131+ Some(name) => {
132+ let mut input = Input::stdin().with_name(Some(name.as_ref()));
133+ input.description.kind = Some("File".to_owned());
134+ input
135+ }
136+ }
137+ }
138+
128139 pub fn from_reader(reader: Box<dyn Read + 'a>) -> Self {
129140 let kind = InputKind::CustomReader(reader);
130141 Input {
@@ -152,11 +163,6 @@ impl<'a> Input<'a> {
152163 self
153164 }
154165
155− pub fn as_file(mut self, provided_name: Option<&OsStr>) -> Self {
156− self.description.kind = Some("File".to_owned());
157− self.with_name(provided_name)
158− }
159−
160166 pub fn description(&self) -> &InputDescription {
161167 &self.description
162168 }