Skip to content

Commit

Permalink
Add --prevent-interpolation flag (#824)
Browse files Browse the repository at this point in the history
  • Loading branch information
denisidoro committed Apr 9, 2023
1 parent a72add9 commit e392055
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/commands/core/actor.rs
Expand Up @@ -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);

Expand Down
4 changes: 4 additions & 0 deletions src/config/cli.rs
Expand Up @@ -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>,
Expand Down
4 changes: 4 additions & 0 deletions src/config/mod.rs
Expand Up @@ -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()
}
Expand Down

0 comments on commit e392055

Please sign in to comment.