From 63e31baa74b242160cc27382e953732de0519406 Mon Sep 17 00:00:00 2001 From: Ulrich Kautz Date: Mon, 24 Jan 2022 16:34:06 +0000 Subject: [PATCH] Add build feature to disable command execution This CL adds the build feature `disable-command-execution` that enforces the `--print` flag and thereby disables execution of commands. --- Cargo.toml | 3 +++ src/config/cli.rs | 1 + src/config/mod.rs | 12 +++++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 5e82540..aacd0f4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,9 @@ keywords = ["cheatsheets", "terminal", "cli", "tui", "shell"] categories = ["command-line-utilities"] license = "Apache-2.0" +[features] +disable-command-execution = [] + [badges] travis-ci = { repository = "denisidoro/navi", branch = "master" } diff --git a/src/config/cli.rs b/src/config/cli.rs index aa633f5..eb5d53a 100644 --- a/src/config/cli.rs +++ b/src/config/cli.rs @@ -97,6 +97,7 @@ pub(super) struct ClapConfig { /// Instead of executing a snippet, prints it to stdout #[clap(long)] + #[cfg(not(feature = "disable-command-execution"))] pub print: bool, /// Returns the best match diff --git a/src/config/mod.rs b/src/config/mod.rs index cb977b1..974cfdf 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -136,8 +136,18 @@ impl Config { self.yaml.style.comment.min_width } + #[cfg(feature = "disable-command-execution")] + fn print(&self) -> bool { + true + } + + #[cfg(not(feature = "disable-command-execution"))] + fn print(&self) -> bool { + self.clap.print + } + pub fn action(&self) -> Action { - if self.clap.print { + if self.print() { Action::Print } else { Action::Execute