-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into expr-file2
- Loading branch information
Showing
4 changed files
with
21 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,10 +52,10 @@ pub(crate) struct Filter { | |
#[arg(long, short)] | ||
discard: Option<String>, | ||
|
||
/// Take filter expressions from <EXPR_FILE> | ||
/// Take a filter expression from <EXPR_FILE> | ||
/// | ||
/// Note: Using a expression file still requires a filter; e.g | ||
/// `[email protected]?`. | ||
/// Note: Do not provide an additional filter expression as an CLI | ||
/// argument! | ||
#[arg(long = "file", short = 'F')] | ||
expr_file: Option<PathBuf>, | ||
|
||
|
@@ -127,6 +127,7 @@ pub(crate) struct Filter { | |
output: Option<OsString>, | ||
|
||
/// A filter expression used for searching | ||
#[arg(default_value = "", hide_default_value = true)] | ||
filter: String, | ||
|
||
/// Read one or more files in normalized PICA+ format | ||
|
@@ -166,7 +167,20 @@ impl Filter { | |
let keep_predicates = | ||
parse_predicates(&self.keep.unwrap_or_default())?; | ||
|
||
let mut filenames = self.filenames; | ||
let filter_str = if let Some(filename) = self.expr_file { | ||
// This "hack" is necessary, because it's not possible to | ||
// distinguish between filter and filenames. If a expression | ||
// file is given, it makes no sense to provide | ||
// an filter expression as CLI argument. | ||
if !self.filter.is_empty() { | ||
if filenames != ["-"] { | ||
filenames.insert(0, self.filter.into()); | ||
} else { | ||
filenames = vec![self.filter.into()]; | ||
} | ||
} | ||
|
||
read_to_string(filename).unwrap() | ||
} else { | ||
self.filter | ||
|
@@ -222,7 +236,7 @@ impl Filter { | |
.strsim_threshold(self.strsim_threshold as f64 / 100.0) | ||
.case_ignore(self.ignore_case); | ||
|
||
'outer: for filename in self.filenames { | ||
'outer: for filename in filenames { | ||
let mut reader = | ||
ReaderBuilder::new().from_path(filename)?; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
bin.name = "pica" | ||
args = "filter -F filter.txt \"003@?\"" | ||
args = "filter -F filter.txt" | ||
status = "success" | ||
stdout = "" | ||
stderr = "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
bin.name = "pica" | ||
args = "filter -F filter.txt \"003@?\"" | ||
args = "filter -F filter.txt" | ||
status = "success" | ||
stderr = "" |