Add --prevent-interpolation flag (#824)

This commit is contained in:
Denis Isidoro 2023-04-08 21:53:48 -03:00 committed by GitHub
parent a72add9d80
commit e3920552ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 0 deletions

View file

@ -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);

View file

@ -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>,

View file

@ -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()
}