diff options
author | Denis Isidoro <denisidoro@users.noreply.github.com> | 2023-04-08 21:53:48 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-08 21:53:48 -0300 |
commit | e3920552ca99bd3f436f548ffdbef7621f7b079d (patch) | |
tree | b40b1f868f59e26154a8407b4e4ac9717bcc0267 | |
parent | a72add9d8038ac037b1cb81d6b7872748003eb02 (diff) |
Add --prevent-interpolation flag (#824)v2.22.0
-rw-r--r-- | src/commands/core/actor.rs | 5 | ||||
-rw-r--r-- | src/config/cli.rs | 4 | ||||
-rw-r--r-- | src/config/mod.rs | 4 |
3 files changed, 13 insertions, 0 deletions
diff --git a/src/commands/core/actor.rs b/src/commands/core/actor.rs index 62bda25..36e2960 100644 --- a/src/commands/core/actor.rs +++ b/src/commands/core/actor.rs @@ -146,6 +146,11 @@ fn unique_result_count(results: &[&str]) -> usize { fn replace_variables_from_snippet(snippet: &str, tags: &str, variables: VariableMap) -> Result<String> { let mut interpolated_snippet = String::from(snippet); + + if CONFIG.prevent_interpolation() { + return Ok(interpolated_snippet); + } + let variables_found: Vec<&str> = deser::VAR_REGEX.find_iter(snippet).map(|m| m.as_str()).collect(); let variable_count = unique_result_count(&variables_found); diff --git a/src/config/cli.rs b/src/config/cli.rs index 431b1da..7e2ec20 100644 --- a/src/config/cli.rs +++ b/src/config/cli.rs @@ -52,6 +52,10 @@ pub(super) struct ClapConfig { #[arg(long)] pub best_match: bool, + /// Prevents variable interpolation + #[arg(long)] + pub prevent_interpolation: bool, + /// Searches for cheatsheets using the tldr-pages repository #[arg(long)] pub tldr: Option<String>, diff --git a/src/config/mod.rs b/src/config/mod.rs index 1126b05..6da5382 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -35,6 +35,10 @@ impl Config { self.clap.best_match } + pub fn prevent_interpolation(&self) -> bool { + self.clap.prevent_interpolation + } + pub fn cmd(&self) -> Option<&Command> { self.clap.cmd.as_ref() } |