Skip to content

Commit

Permalink
new: object flattening feature
Browse files Browse the repository at this point in the history
  • Loading branch information
pamburus committed May 1, 2024
1 parent 377359b commit e51f01a
Show file tree
Hide file tree
Showing 8 changed files with 411 additions and 54 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ members = [".", "crate/encstr"]
[workspace.package]
repository = "https://github.com/pamburus/hl"
authors = ["Pavel Ivanov <[email protected]>"]
version = "0.28.2-alpha.2"
version = "0.29.0-alpha.1"
edition = "2021"
license = "MIT"

Expand Down Expand Up @@ -95,6 +95,7 @@ wildmatch = "2"
[profile.release]
debug = false
opt-level = 3
inline-threshold = 500
codegen-units = 1
lto = true

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ Output Options:
--no-raw Disable raw source messages output, overrides --raw option
--raw-fields Output field values as is, without unescaping or prettifying
-h, --hide <KEY> Hide or reveal fields with the specified keys, prefix with ! to reveal, specify '!*' to reveal all
--flatten <WHEN> Whether to flatten objects [default: always] [possible values: never, always]
-t, --time-format <FORMAT> Time format, see https://man7.org/linux/man-pages/man1/date.1.html [env: HL_TIME_FORMAT=] [default: "%b %d %T.%3N"]
-Z, --time-zone <TZ> Time zone name, see column "TZ identifier" at https://en.wikipedia.org/wiki/List_of_tz_database_time_zones [env: HL_TIME_ZONE=] [default: UTC]
-L, --local Use local time zone, overrides --time-zone option
Expand Down
4 changes: 3 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ pub struct Options {
pub tail: u64,
pub delimiter: Delimiter,
pub unix_ts_unit: Option<UnixTimestampUnit>,
pub flatten: bool,
}

impl Options {
Expand Down Expand Up @@ -639,7 +640,8 @@ impl App {
self.options.fields.filter.clone(),
self.options.formatting.clone(),
)
.with_field_unescaping(!self.options.raw_fields),
.with_field_unescaping(!self.options.raw_fields)

Check warning on line 643 in src/app.rs

View check run for this annotation

Codecov / codecov/patch

src/app.rs#L643

Added line #L643 was not covered by tests
.with_flatten(self.options.flatten),
)
}
}
Expand Down
17 changes: 17 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,17 @@ pub struct Opt {
)]
pub hide: Vec<String>,

/// Whether to flatten objects.
#[arg(
long,
value_name = "WHEN",
value_enum,
default_value = "always",
overrides_with = "flatten",
help_heading = heading::OUTPUT
)]
pub flatten: FlattenOption,

/// Time format, see https://man7.org/linux/man-pages/man1/date.1.html.
#[arg(
short,
Expand Down Expand Up @@ -360,6 +371,12 @@ pub enum UnixTimestampUnit {
Ns,
}

#[derive(ValueEnum, Debug, Clone, Copy, PartialEq, Eq)]
pub enum FlattenOption {
Never,
Always,
}

mod heading {
pub const FILTERING: &str = "Filtering Options";
pub const INPUT: &str = "Input Options";
Expand Down
Loading

0 comments on commit e51f01a

Please sign in to comment.