Skip to content

Commit

Permalink
Merge pull request #41 from pamburus/release/0.15.x
Browse files Browse the repository at this point in the history
new: Now colon delimiter can be used in `--filter` command line option
  • Loading branch information
pamburus authored Jun 10, 2023
2 parents 854ae6e + 8c770b9 commit 17b45d8
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 25 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.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
3 changes: 3 additions & 0 deletions benches/go/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/pamburus/hl/benches/go

go 1.20
6 changes: 4 additions & 2 deletions benches/parse-and-format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use criterion::{criterion_group, criterion_main, Criterion};
// local imports
use hl::{
timezone::Tz, DateTimeFormatter, Filter, IncludeExcludeKeyFilter, LinuxDateFormat, Parser,
ParserSettings, RecordFormatter, SegmentProcesor, Settings, Theme,
ParserSettings, RecordFormatter, SegmentProcessor, Settings, Theme,
settings,
};

// ---
Expand All @@ -29,9 +30,10 @@ fn benchmark(c: &mut Criterion) {
),
false,
Arc::new(IncludeExcludeKeyFilter::default()),
settings::Formatting::default(),
);
let filter = Filter::default();
let mut processor = SegmentProcesor::new(&parser, &mut formatter, &filter);
let mut processor = SegmentProcessor::new(&parser, &mut formatter, &filter);
let mut buf = Vec::new();
b.iter(|| {
processor.run(record, &mut buf);
Expand Down
6 changes: 3 additions & 3 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl App {
self.options.formatting.clone(),
)
.with_field_unescaping(!self.options.raw_fields);
let mut processor = SegmentProcesor::new(&parser, &mut formatter, &self.options.filter);
let mut processor = SegmentProcessor::new(&parser, &mut formatter, &self.options.filter);
for segment in rxi.iter() {
match segment {
Segment::Complete(segment) => {
Expand Down Expand Up @@ -144,13 +144,13 @@ impl App {

// ---

pub struct SegmentProcesor<'a> {
pub struct SegmentProcessor<'a> {
parser: &'a Parser,
formatter: &'a mut RecordFormatter,
filter: &'a Filter,
}

impl<'a> SegmentProcesor<'a> {
impl<'a> SegmentProcessor<'a> {
pub fn new(parser: &'a Parser, formatter: &'a mut RecordFormatter, filter: &'a Filter) -> Self {
Self {
parser,
Expand Down
2 changes: 1 addition & 1 deletion src/eseq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub enum Mode {
SlowBlink,
RapidBlink,
Reverse,
Conseal,
Conceal,
CrossedOut,
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ mod scanning;
pub mod signal;

// public uses
pub use app::{App, FieldOptions, Options, SegmentProcesor};
pub use app::{App, FieldOptions, Options, SegmentProcessor};
pub use datefmt::{DateTimeFormatter, LinuxDateFormat};
pub use filtering::DefaultNormalizing;
pub use formatting::RecordFormatter;
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
2 changes: 1 addition & 1 deletion src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ pub struct Field {

// ---

#[derive(Debug, Deserialize, Clone)]
#[derive(Clone, Debug, Default, Deserialize)]
pub struct Formatting {
pub punctuation: Punctuation,
}
Expand Down
2 changes: 1 addition & 1 deletion src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl From<&themecfg::Style> for Style {
codes.push(
match mode {
themecfg::Mode::Bold => Mode::Bold,
themecfg::Mode::Conseal => Mode::Conseal,
themecfg::Mode::Conceal => Mode::Conceal,
themecfg::Mode::CrossedOut => Mode::CrossedOut,
themecfg::Mode::Faint => Mode::Faint,
themecfg::Mode::Italic => Mode::Italic,
Expand Down
2 changes: 1 addition & 1 deletion src/themecfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ pub enum Mode {
SlowBlink,
RapidBlink,
Reverse,
Conseal,
Conceal,
CrossedOut,
}

Expand Down

0 comments on commit 17b45d8

Please sign in to comment.