Skip to content

Commit

Permalink
Merge pull request #32 from pamburus/release/0.12.0
Browse files Browse the repository at this point in the history
release 0.12.0
  • Loading branch information
pamburus authored Aug 25, 2022
2 parents 65aad52 + c0be681 commit 3b2adfe
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 26 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.11.2"
version = "0.12.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,15 @@ Log viewer which translates JSON logs into pretty human-readable representation.
- Command
```
$ hl example.log --show provider
$ hl example.log --hide '*' --hide '!provider'
```
Hides all fields except `provider`.
- Command
```
$ hl example.log -h headers -h body -H headers.content-type
$ hl example.log -h headers -h body -h '!headers.content-type'
```
Hides fields `headers` and `body` but shows a single sub-field `content-type` inside field `headers`.
Expand Down Expand Up @@ -297,7 +297,7 @@ Log viewer which translates JSON logs into pretty human-readable representation.
### Complete set of options and flags
```
hl 0.11.0
hl 0.12.0
JSON log converter to human readable representation

USAGE:
Expand All @@ -314,8 +314,7 @@ OPTIONS:
-e, --hide-empty-fields Hide empty fields, applies for null, string, object and array fields only [env: HL_HIDE_EMPTY_FIELDS=]
-E, --show-empty-fields Show empty fields, overrides --hide-empty-fields option [env: HL_SHOW_EMPTY_FIELDS=]
-f, --filter <FILTER> Filtering by field values in one of forms [<key>=<value>, <key>~=<value>, <key>~~=<value>, <key>!=<value>, <key>!~=<value>, <key>!~~=<value>] where ~ denotes substring match and ~~ denotes regular expression match
-h, --hide <HIDE> Hide fields with the specified keys
-H, --show <SHOW> Hide all fields except fields with the specified keys
-h, --hide <HIDE> Hide or unhide fields with the specified keys, prefix with ! to unhide, specify !* to unhide all
--help Print help information
--interrupt-ignore-count <INTERRUPT_IGNORE_COUNT> Number of interrupts to ignore, i.e. Ctrl-C (SIGINT) [env: HL_INTERRUPT_IGNORE_COUNT=] [default: 3]
-l, --level <LEVEL> Filtering by level [env: HL_LEVEL=] [possible values: error, warning, info, debug]
Expand All @@ -328,7 +327,6 @@ OPTIONS:
--since <SINCE> Filtering by timestamp >= the value (--time-zone and --local options are honored)
-t, --time-format <TIME_FORMAT> Time format, see https://man7.org/linux/man-pages/man1/date.1.html [env: HL_TIME_FORMAT=] [default: "%y-%m-%d %T.%3N"]
--theme <THEME> Color theme [env: HL_THEME=] [default: one-dark-green]
-u, --unhide <UNHIDE> Unhide fields with the specified keys
--until <UNTIL> Filtering by timestamp <= the value (--time-zone and --local options are honored)
-V, --version Print version information
-Z, --time-zone <TIME_ZONE> Time zone name, see column "TZ database name" at https://en.wikipedia.org/wiki/List_of_tz_database_time_zones [env: HL_TIME_ZONE=] [default: UTC]
Expand Down
10 changes: 10 additions & 0 deletions src/filtering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,21 @@ impl<N: KeyNormalize> IncludeExcludeKeyFilter<N> {
self
}

pub fn included(mut self) -> Self {
self.setting = IncludeExcludeSetting::Include;
self
}

pub fn exclude(&mut self) -> &mut Self {
self.setting = IncludeExcludeSetting::Exclude;
self
}

pub fn excluded(mut self) -> Self {
self.setting = IncludeExcludeSetting::Exclude;
self
}

pub fn setting(&self) -> IncludeExcludeSetting {
self.setting.clone()
}
Expand Down
39 changes: 21 additions & 18 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,10 @@ struct Opt {
#[clap(short, long, number_of_values = 1)]
filter: Vec<String>,
//
/// Hide fields with the specified keys.
/// Hide or unhide fields with the specified keys, prefix with ! to unhide, specify !* to unhide all.
#[clap(long, short = 'h', number_of_values = 1)]
hide: Vec<String>,
//
/// Hide all fields except fields with the specified keys.
#[structopt(long, short = 'H', number_of_values = 1)]
show: Vec<String>,
//
/// Unhide fields with the specified keys.
#[structopt(long, short = 'u', number_of_values = 1)]
unhide: Vec<String>,
//
/// Filtering by level.
#[clap(short, long, env = "HL_LEVEL", overrides_with = "level")]
#[clap(arg_enum)]
Expand Down Expand Up @@ -300,15 +292,26 @@ fn run() -> Result<()> {
let hide_empty_fields = !opt.show_empty_fields && opt.hide_empty_fields;

// Configure field filter.
let mut fields = IncludeExcludeKeyFilter::new(KeyMatchOptions::default());
if opt.hide.len() == 0 && opt.show.len() != 0 {
fields.exclude();
}
for key in CONFIG.fields.hide.iter().chain(&opt.hide) {
fields.entry(&key).exclude();
}
for key in opt.show.iter().chain(&opt.unhide) {
fields.entry(&key).include();
let all = || IncludeExcludeKeyFilter::new(KeyMatchOptions::default());
let none = || all().excluded();
let mut fields = all();
for (i, key) in CONFIG.fields.hide.iter().chain(&opt.hide).enumerate() {
if key == "*" {
fields = none();
} else if key == "!*" {
fields = all();
} else if key.starts_with("!") {
if i == 0 {
fields = none();
}
fields.entry(&key[1..]).include();
} else if key.starts_with("\\!") {
fields.entry(&key[1..]).exclude();
} else if key.starts_with("\\\\") {
fields.entry(&key[1..]).exclude();
} else {
fields.entry(&key).exclude();
}
}

let max_message_size = opt.max_message_size;
Expand Down

0 comments on commit 3b2adfe

Please sign in to comment.