Skip to content

Commit

Permalink
new: now colon delimiter can be used in --filter command line option
Browse files Browse the repository at this point in the history
  • Loading branch information
pamburus committed Jun 10, 2023
1 parent 91faac1 commit 8c770b9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ categories = ["command-line-utilities"]
description = "Utility for viewing json-formatted log files."
keywords = ["cli", "human", "log"]
name = "hl"
version = "0.15.2-alpha.1"
version = "0.15.2"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
32 changes: 19 additions & 13 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,20 +482,26 @@ pub struct FieldFilter {

impl FieldFilter {
fn parse(text: &str) -> Result<Self> {
let mut parts = text.split('=');
match (parts.next(), parts.next()) {
(Some(key), Some(value)) => {
let (key, match_policy, op) = Self::parse_mp_op(key, value)?;
let flat_key = key.as_bytes().iter().position(|&x| x == b'.').is_none();
Ok(Self {
key: key.into(),
match_policy,
op,
flat_key,
})
}
_ => Err(Error::WrongFieldFilter(text.into())),
let parse = |key, value| {
let (key, match_policy, op) = Self::parse_mp_op(key, value)?;
let flat_key = key.as_bytes().iter().position(|&x| x == b'.').is_none();
Ok(Self {
key: key.into(),
match_policy,
op,
flat_key,
})
};

if let Some(index) = text.find('=') {
return parse(&text[0..index], &text[index+1..]);
}

if let Some(index) = text.find(':') {
return parse(&text[0..index], &text[index+1..]);
}

Err(Error::WrongFieldFilter(text.into()))
}

fn parse_mp_op<'k>(
Expand Down

0 comments on commit 8c770b9

Please sign in to comment.