summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis Isidoro <denisidoro@users.noreply.github.com>2023-04-08 21:53:48 -0300
committerGitHub <noreply@github.com>2023-04-08 21:53:48 -0300
commite3920552ca99bd3f436f548ffdbef7621f7b079d (patch)
treeb40b1f868f59e26154a8407b4e4ac9717bcc0267
parenta72add9d8038ac037b1cb81d6b7872748003eb02 (diff)
Add --prevent-interpolation flag (#824)v2.22.0
-rw-r--r--src/commands/core/actor.rs5
-rw-r--r--src/config/cli.rs4
-rw-r--r--src/config/mod.rs4
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()
}