on master help sign in
Remove Input.as_file and add Input::stdin_as_file
7a9decaEthan P
src/bin/bat/app.rs+3−3
@@ -257,7 +257,7 @@ impl App {
257 let files: Option<Vec<&OsStr>> = self.matches.values_of_os("FILE").map(|vs| vs.collect());
257 let files: Option<Vec<&OsStr>> = self.matches.values_of_os("FILE").map(|vs| vs.collect());
258
258
259 if files.is_none() {
259 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));
261 return Ok(vec![input]);
261 return Ok(vec![input]);
262 }
262 }
263 let files_or_none: Box<dyn Iterator<Item = _>> = match files {
263 let files_or_none: Box<dyn Iterator<Item = _>> = match files {
@@ -269,9 +269,9 @@ impl App {
269 for (filepath, provided_name) in files_or_none.zip(filenames_or_none) {
269 for (filepath, provided_name) in files_or_none.zip(filenames_or_none) {
270 if let Some(filepath) = filepath {
270 if let Some(filepath) = filepath {
271 if filepath.to_str().unwrap_or_default() == "-" {
271 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));
273 } else {
273 } 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));
275 }
275 }
276 }
276 }
277 }
277 }
src/input.rs+11−5
@@ -125,6 +125,17 @@ impl<'a> Input<'a> {
125 }
125 }
126 }
126 }
127
127
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+
128 pub fn from_reader(reader: Box<dyn Read + 'a>) -> Self {
139 pub fn from_reader(reader: Box<dyn Read + 'a>) -> Self {
129 let kind = InputKind::CustomReader(reader);
140 let kind = InputKind::CustomReader(reader);
130 Input {
141 Input {
@@ -152,11 +163,6 @@ impl<'a> Input<'a> {
152 self
163 self
153 }
164 }
154
165
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−
160 pub fn description(&self) -> &InputDescription {
166 pub fn description(&self) -> &InputDescription {
161 &self.description
167 &self.description
162 }
168 }