From 7a9decad709c5bee97f682e1641740f33b2d0a36 Mon Sep 17 00:00:00 2001 From: Ethan P Date: Wed, 27 May 2020 15:40:57 -0700 Subject: [PATCH] Remove Input.as_file and add Input::stdin_as_file --- src/bin/bat/app.rs | 6 +++--- src/input.rs | 16 +++++++++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs index 7b514901..b97d3ab8 100644 --- a/src/bin/bat/app.rs +++ b/src/bin/bat/app.rs @@ -257,7 +257,7 @@ impl App { let files: Option> = self.matches.values_of_os("FILE").map(|vs| vs.collect()); if files.is_none() { - let input = Input::stdin().as_file(filenames_or_none.next().unwrap_or(None)); + let input = Input::stdin_as_file(filenames_or_none.next().unwrap_or(None)); return Ok(vec![input]); } let files_or_none: Box> = match files { @@ -269,9 +269,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() == "-" { - file_input.push(Input::stdin().as_file(provided_name)); + file_input.push(Input::stdin_as_file(provided_name)); } else { - file_input.push(Input::ordinary_file(filepath).as_file(provided_name)); + file_input.push(Input::ordinary_file(filepath).with_name(provided_name)); } } } diff --git a/src/input.rs b/src/input.rs index 55fbbf03..04a3e5bb 100644 --- a/src/input.rs +++ b/src/input.rs @@ -125,6 +125,17 @@ impl<'a> Input<'a> { } } + pub fn stdin_as_file(name: Option>) -> Self { + match name { + None => Input::stdin(), + Some(name) => { + let mut input = Input::stdin().with_name(Some(name.as_ref())); + input.description.kind = Some("File".to_owned()); + input + } + } + } + pub fn from_reader(reader: Box) -> Self { let kind = InputKind::CustomReader(reader); Input { @@ -152,11 +163,6 @@ impl<'a> Input<'a> { self } - pub fn as_file(mut self, provided_name: Option<&OsStr>) -> Self { - self.description.kind = Some("File".to_owned()); - self.with_name(provided_name) - } - pub fn description(&self) -> &InputDescription { &self.description }