Skip to content

Commit

Permalink
Add no-builtin-keywords flag to CLI options
Browse files Browse the repository at this point in the history
  • Loading branch information
bensadeh committed Oct 12, 2024
1 parent 804fe35 commit aa524b0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
6 changes: 5 additions & 1 deletion src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,12 @@ pub struct Cli {
#[clap(long = "disable-json")]
pub disable_json: bool,

/// Disable the highlighting of all builtin keyword groups (booleans, nulls, log severities and common REST verbs)
#[clap(long = "no-builtin-keywords")]
pub no_builtin_keywords: bool,

/// Suppress all output (for debugging and benchmarking)
#[clap(long = "hidden-suppress-output", hide = true)]
#[clap(long = "suppress-output", hide = true)]
pub suppress_output: bool,

/// Print completions to stdout
Expand Down
25 changes: 18 additions & 7 deletions src/highlighter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use inlet_manifold::*;
pub fn get_highlighter(
highlighter_groups: HighlighterGroups,
theme: Theme,
enable_builtin_keywords: bool,
keyword_configs_from_cli: Vec<KeywordConfig>,
disable_builtin_keywords: bool,
) -> Result<Highlighter, Error> {
let mut builder = Highlighter::builder();

Expand Down Expand Up @@ -53,11 +54,14 @@ pub fn get_highlighter(
}

{
let keywords = if enable_builtin_keywords {
theme.keywords.into_iter().chain(get_builtin_keywords()).collect()
} else {
theme.keywords
};
let builtin_keywords = get_builtin_keywords(disable_builtin_keywords);

let keywords = vec![]
.into_iter()
.chain(theme.keywords)
.chain(builtin_keywords)
.chain(keyword_configs_from_cli)
.collect();

builder.with_keyword_highlighter(keywords);
}
Expand All @@ -75,7 +79,14 @@ pub fn get_highlighter(
builder.build()
}

fn get_builtin_keywords() -> Vec<KeywordConfig> {
fn get_builtin_keywords(disable_builtin_keywords: bool) -> Vec<KeywordConfig> {
match disable_builtin_keywords {
true => vec![],
false => builtin_keywords(),
}
}

fn builtin_keywords() -> Vec<KeywordConfig> {
let severity_levels = vec![
KeywordConfig {
words: vec!["ERROR".to_string()],
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async fn main() -> Result<()> {
let highlighter_groups = groups::get_highlighter_groups(cli_options)?;

let new_theme = reader::parse_theme(cli.config_path.clone())?;
let highlighter = highlighter::get_highlighter(highlighter_groups, new_theme, true)?;
let highlighter = highlighter::get_highlighter(highlighter_groups, new_theme, vec![], cli.no_builtin_keywords)?;

run(highlighter, config).await;

Expand Down

0 comments on commit aa524b0

Please sign in to comment.