Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new: Improved value names in command line options #221

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

2 changes: 1 addition & 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 <mr.pavel.ivanov@gmail.com>"]
version = "0.28.1-alpha.4"
version = "0.28.1-alpha.5"
edition = "2021"
license = "MIT"

Expand Down
78 changes: 39 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -458,45 +458,45 @@ Arguments:
[FILE]... Files to process

Options:
-c, --color [<COLOR>] Color output options [env: HL_COLOR=] [default: auto] [possible values: auto, always, never]
--paging <PAGING> Output paging options [env: HL_PAGING=] [default: auto] [possible values: auto, always, never]
-P Handful alias for --paging=never, overrides --paging option
--theme <THEME> Color theme [env: HL_THEME=] [default: universal]
-r, --raw Output raw source messages instead of formatter messages, it can be useful for applying filters and saving results in original format
--no-raw Disable raw source messages output, overrides --raw option
--raw-fields Disable unescaping and prettifying of field values
--allow-prefix Allow non-JSON prefixes before JSON messages [env: HL_ALLOW_PREFIX=]
--interrupt-ignore-count <INTERRUPT_IGNORE_COUNT> Number of interrupts to ignore, i.e. Ctrl-C (SIGINT) [env: HL_INTERRUPT_IGNORE_COUNT=] [default: 3]
--buffer-size <BUFFER_SIZE> Buffer size [env: HL_BUFFER_SIZE=] [default: "256 KiB"]
--max-message-size <MAX_MESSAGE_SIZE> Maximum message size [env: HL_MAX_MESSAGE_SIZE=] [default: "64 MiB"]
-C, --concurrency <CONCURRENCY> Number of processing threads [env: HL_CONCURRENCY=]
-f, --filter <FILTER> Filtering by field values in one of forms [k=v, k~=v, k~~=v, 'k!=v', 'k!~=v', 'k!~~=v'] where ~ does substring match and ~~ does regular expression match
-q, --query <QUERY> Custom query, accepts expressions from --filter and supports '(', ')', 'and', 'or', 'not', 'in', 'contain', 'like', '<', '>', '<=', '>=', etc
-h, --hide <HIDE> Hide or reveal fields with the specified keys, prefix with ! to reveal, specify '!*' to reveal all
-l, --level <LEVEL> Filtering by level [env: HL_LEVEL=]
--since <SINCE> Filtering by timestamp >= the value (--time-zone and --local options are honored)
--until <UNTIL> 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: "%b %d %T.%3N"]
-Z, --time-zone <TIME_ZONE> 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
--no-local Disable local time zone, overrides --local option
--unix-timestamp-unit <UNIX_TIMESTAMP_UNIT> Unix timestamp unit [env: HL_UNIX_TIMESTAMP_UNIT=] [default: auto] [possible values: auto, s, ms, us, ns]
-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=]
--input-info <INPUT_INFO> Show input number and/or input filename before each message [default: auto] [possible values: auto, none, full, compact, minimal]
--list-themes List available themes and exit
-s, --sort Sort messages chronologically
-F, --follow Follow input streams and sort messages chronologically during time frame set by --sync-interval-ms option
--tail <TAIL> Number of last messages to preload from each file in --follow mode [default: 10]
--sync-interval-ms <SYNC_INTERVAL_MS> Synchronization interval for live streaming mode enabled by --follow option [default: 100]
-o, --output <OUTPUT> Output file
--delimiter <DELIMITER> Log message delimiter, [NUL, CR, LF, CRLF] or any custom string
--input-format <INPUT_FORMAT> Input format [env: HL_INPUT_FORMAT=] [default: auto] [possible values: auto, json, logfmt]
--dump-index Dump index metadata and exit
--debug Print debug error messages that can help with troubleshooting
--shell-completions <SHELL_COMPLETIONS> Print shell auto-completion script and exit [possible values: bash, elvish, fish, powershell, zsh]
--help Print help
-V, --version Print version
-c, --color [<WHEN>] Color output options [env: HL_COLOR=] [default: auto] [possible values: auto, always, never]
--paging <WHEN> Output paging options [env: HL_PAGING=] [default: auto] [possible values: auto, always, never]
-P Handful alias for --paging=never, overrides --paging option
--theme <THEME> Color theme [env: HL_THEME=] [default: universal]
-r, --raw Output raw source messages instead of formatter messages, it can be useful for applying filters and saving results in original format
--no-raw Disable raw source messages output, overrides --raw option
--raw-fields Disable unescaping and prettifying of field values
--allow-prefix Allow non-JSON prefixes before JSON messages [env: HL_ALLOW_PREFIX=]
--interrupt-ignore-count <N> Number of interrupts to ignore, i.e. Ctrl-C (SIGINT) [env: HL_INTERRUPT_IGNORE_COUNT=] [default: 3]
--buffer-size <SIZE> Buffer size [env: HL_BUFFER_SIZE=] [default: "256 KiB"]
--max-message-size <SIZE> Maximum message size [env: HL_MAX_MESSAGE_SIZE=] [default: "64 MiB"]
-C, --concurrency <N> Number of processing threads [env: HL_CONCURRENCY=]
-f, --filter <FILTER> Filtering by field values in one of forms [k=v, k~=v, k~~=v, 'k!=v', 'k!~=v', 'k!~~=v'] where ~ does substring match and ~~ does regular expression match
-q, --query <QUERY> Custom query, accepts expressions from --filter and supports '(', ')', 'and', 'or', 'not', 'in', 'contain', 'like', '<', '>', '<=', '>=', etc
-h, --hide <KEY> Hide or reveal fields with the specified keys, prefix with ! to reveal, specify '!*' to reveal all
-l, --level <LEVEL> Filtering by level [env: HL_LEVEL=]
--since <TIME> Filtering by timestamp >= the value (--time-zone and --local options are honored)
--until <TIME> Filtering by timestamp <= the value (--time-zone and --local options are honored)
-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
--no-local Disable local time zone, overrides --local option
--unix-timestamp-unit <UNIT> Unix timestamp unit [env: HL_UNIX_TIMESTAMP_UNIT=] [default: auto] [possible values: auto, s, ms, us, ns]
-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=]
--input-info <VARIANT> Show input number and/or input filename before each message [default: auto] [possible values: auto, none, full, compact, minimal]
--list-themes List available themes and exit
-s, --sort Sort messages chronologically
-F, --follow Follow input streams and sort messages chronologically during time frame set by --sync-interval-ms option
--tail <N> Number of last messages to preload from each file in --follow mode [default: 10]
--sync-interval-ms <MILLISECONDS> Synchronization interval for live streaming mode enabled by --follow option [default: 100]
-o, --output <FILE> Output file
--delimiter <DELIMITER> Log message delimiter, [NUL, CR, LF, CRLF] or any custom string
--input-format <FORMAT> Input format [env: HL_INPUT_FORMAT=] [default: auto] [possible values: auto, json, logfmt]
--dump-index Dump index metadata and exit
--debug Print debug error messages that can help with troubleshooting
--shell-completions <SHELL> Print shell auto-completion script and exit [possible values: bash, elvish, fish, powershell, zsh]
--help Print help
-V, --version Print version
```

## Performance
Expand Down
91 changes: 71 additions & 20 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,28 @@ use crate::{
#[clap(version, disable_help_flag = true)]
pub struct Opt {
/// Color output options.
#[arg(long, short, default_value = "auto", env = "HL_COLOR", overrides_with = "color", default_missing_value = "always", num_args = 0..=1)]
#[arg(value_enum)]
#[arg(
long,
short,
default_value = "auto",
env = "HL_COLOR",
overrides_with = "color",
default_missing_value = "always",
num_args = 0..=1,
value_name = "WHEN",
value_enum
)]
pub color: ColorOption,

/// Output paging options.
#[arg(long, default_value = "auto", env = "HL_PAGING", overrides_with = "paging")]
#[arg(value_enum)]
#[arg(
long,
default_value = "auto",
env = "HL_PAGING",
overrides_with = "paging",
value_name = "WHEN",
value_enum
)]
pub paging: PagingOption,

/// Handful alias for --paging=never, overrides --paging option.
Expand All @@ -38,7 +53,7 @@ pub struct Opt {
long,
default_value_t = config::get().theme.clone(),
env = "HL_THEME",
overrides_with="theme",
overrides_with="theme"
)]
pub theme: String,

Expand All @@ -63,20 +78,41 @@ pub struct Opt {
long,
default_value = "3",
env = "HL_INTERRUPT_IGNORE_COUNT",
overrides_with = "interrupt_ignore_count"
overrides_with = "interrupt_ignore_count",
value_name = "N"
)]
pub interrupt_ignore_count: usize,

/// Buffer size.
#[arg(long, default_value = "256 KiB", env="HL_BUFFER_SIZE", value_parser = parse_non_zero_size, overrides_with="buffer_size")]
#[arg(
long,
default_value = "256 KiB",
env="HL_BUFFER_SIZE",
value_parser = parse_non_zero_size,
overrides_with="buffer_size",
value_name = "SIZE"
)]
pub buffer_size: NonZeroUsize,

/// Maximum message size.
#[arg(long, default_value = "64 MiB", env="HL_MAX_MESSAGE_SIZE", value_parser = parse_non_zero_size, overrides_with="max_message_size")]
#[arg(
long,
default_value = "64 MiB",
env="HL_MAX_MESSAGE_SIZE",
value_parser = parse_non_zero_size,
overrides_with="max_message_size",
value_name = "SIZE"
)]
pub max_message_size: NonZeroUsize,

/// Number of processing threads.
#[arg(long, short = 'C', env = "HL_CONCURRENCY", overrides_with = "concurrency")]
#[arg(
long,
short = 'C',
env = "HL_CONCURRENCY",
overrides_with = "concurrency",
value_name = "N"
)]
pub concurrency: Option<usize>,

/// Filtering by field values in one of forms [k=v, k~=v, k~~=v, 'k!=v', 'k!~=v', 'k!~~=v'] where ~ does substring match and ~~ does regular expression match.
Expand All @@ -88,7 +124,7 @@ pub struct Opt {
pub query: Vec<String>,

/// Hide or reveal fields with the specified keys, prefix with ! to reveal, specify '!*' to reveal all.
#[arg(long, short = 'h', number_of_values = 1)]
#[arg(long, short = 'h', number_of_values = 1, value_name = "KEY")]
pub hide: Vec<String>,

/// Filtering by level.
Expand All @@ -97,11 +133,11 @@ pub struct Opt {
pub level: Option<RelaxedLevel>,

/// Filtering by timestamp >= the value (--time-zone and --local options are honored).
#[arg(long, allow_hyphen_values = true, overrides_with = "since")]
#[arg(long, allow_hyphen_values = true, overrides_with = "since", value_name = "TIME")]
pub since: Option<String>,

/// Filtering by timestamp <= the value (--time-zone and --local options are honored).
#[arg(long, allow_hyphen_values = true, overrides_with = "until")]
#[arg(long, allow_hyphen_values = true, overrides_with = "until", value_name = "TIME")]
pub until: Option<String>,

/// Time format, see https://man7.org/linux/man-pages/man1/date.1.html.
Expand All @@ -111,11 +147,19 @@ pub struct Opt {
env="HL_TIME_FORMAT",
default_value_t = config::get().time_format.clone(),
overrides_with = "time_format",
value_name = "FORMAT",
)]
pub time_format: String,

/// Time zone name, see column "TZ identifier" at https://en.wikipedia.org/wiki/List_of_tz_database_time_zones.
#[arg(long, short = 'Z', env="HL_TIME_ZONE", default_value = config::get().time_zone.name(), overrides_with="time_zone")]
#[arg(
long,
short = 'Z',
env="HL_TIME_ZONE",
default_value = config::get().time_zone.name(),
overrides_with="time_zone",
value_name = "TZ"
)]
pub time_zone: chrono_tz::Tz,

/// Use local time zone, overrides --time-zone option.
Expand All @@ -131,7 +175,8 @@ pub struct Opt {
long,
default_value = "auto",
overrides_with = "unix_timestamp_unit",
env = "HL_UNIX_TIMESTAMP_UNIT"
env = "HL_UNIX_TIMESTAMP_UNIT",
value_name = "UNIT"
)]
pub unix_timestamp_unit: UnixTimestampUnit,

Expand All @@ -158,7 +203,7 @@ pub struct Opt {
pub show_empty_fields: bool,

/// Show input number and/or input filename before each message.
#[arg(long, default_value = "auto", overrides_with = "input_info")]
#[arg(long, default_value = "auto", overrides_with = "input_info", value_name = "VARIANT")]
#[arg(value_enum)]
pub input_info: InputInfoOption,

Expand All @@ -175,15 +220,20 @@ pub struct Opt {
pub follow: bool,

/// Number of last messages to preload from each file in --follow mode.
#[arg(long, default_value = "10", overrides_with = "tail")]
#[arg(long, default_value = "10", overrides_with = "tail", value_name = "N")]
pub tail: u64,

/// Synchronization interval for live streaming mode enabled by --follow option.
#[arg(long, default_value = "100", overrides_with = "sync_interval_ms")]
#[arg(
long,
default_value = "100",
overrides_with = "sync_interval_ms",
value_name = "MILLISECONDS"
)]
pub sync_interval_ms: u64,

/// Output file.
#[arg(long, short = 'o', overrides_with = "output")]
#[arg(long, short = 'o', overrides_with = "output", value_name = "FILE")]
pub output: Option<String>,

/// Log message delimiter, [NUL, CR, LF, CRLF] or any custom string.
Expand All @@ -195,7 +245,8 @@ pub struct Opt {
long,
env = "HL_INPUT_FORMAT",
default_value = "auto",
overrides_with = "input_format"
overrides_with = "input_format",
value_name = "FORMAT"
)]
pub input_format: InputFormat,

Expand All @@ -208,7 +259,7 @@ pub struct Opt {
pub debug: bool,

/// Print shell auto-completion script and exit.
#[arg(long, value_parser = value_parser!(Shell))]
#[arg(long, value_parser = value_parser!(Shell), value_name = "SHELL")]
pub shell_completions: Option<Shell>,

/// Print help.
Expand Down
7 changes: 6 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@ use crate::settings::Settings;

pub const APP_NAME: &str = "hl";

static CONFIG: Lazy<Settings> = Lazy::new(|| load());
static CONFIG: Lazy<Settings> = Lazy::new(load);
static DEFAULT: Lazy<Settings> = Lazy::new(Settings::default);

pub fn get() -> &'static Settings {
&CONFIG
}

pub fn default() -> &'static Settings {
&DEFAULT
}

pub fn app_dirs() -> AppDirs {
AppDirs::new(Some(APP_NAME), true).unwrap()
}
Expand Down
Loading