From b5b79b4bf24ecc223fc48b9dce375d73ff8c9dd9 Mon Sep 17 00:00:00 2001 From: Ulrich Kautz Date: Wed, 9 Feb 2022 10:23:50 +0000 Subject: [PATCH] Add build feature to disable repo management Having a command to install cheatsheets from repositories on github is amazing and makes `navi` very easy to setup and get started. The repo contents provide the "meat" of `navi`. A one-liner can load a bunch of useful cheatsheets for a whole host of open source commands. However, in locked down environments, where a high level of control of what is executed needs to be imposed, having the capability to download and use "arbitrary code from the internet" can be more harmful than good. Here you would likely want to manage all cheathsheets for `navi` carefully yourself. Possibly reviewing each cheathsheet individually. This CL provides a build feature that disables the whole `repo` sub-command tree to support that use-case. --- Cargo.toml | 1 + src/config/cli.rs | 1 + src/handler/mod.rs | 5 ++++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index aacd0f4..ecdf330 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ license = "Apache-2.0" [features] disable-command-execution = [] +disable-repo-management = [] [badges] travis-ci = { repository = "denisidoro/navi", branch = "master" } diff --git a/src/config/cli.rs b/src/config/cli.rs index eb5d53a..3a62aca 100644 --- a/src/config/cli.rs +++ b/src/config/cli.rs @@ -153,6 +153,7 @@ pub enum Command { args: Vec, }, /// Manages cheatsheet repositories + #[cfg(not(feature = "disable-repo-management"))] Repo { #[clap(subcommand)] cmd: RepoCommand, diff --git a/src/handler/mod.rs b/src/handler/mod.rs index 4678810..d43db58 100644 --- a/src/handler/mod.rs +++ b/src/handler/mod.rs @@ -8,7 +8,9 @@ pub mod repo_add; pub mod repo_browse; pub mod shell; -use crate::config::Command::{Fn, Info, Preview, PreviewVar, PreviewVarStdin, Repo, Widget}; +#[cfg(not(feature = "disable-repo-management"))] +use crate::config::Command::Repo; +use crate::config::Command::{Fn, Info, Preview, PreviewVar, PreviewVarStdin, Widget}; use crate::config::{RepoCommand, CONFIG}; use crate::handler; use anyhow::Context; @@ -38,6 +40,7 @@ pub fn handle() -> Result<()> { handler::info::main(info).with_context(|| format!("Failed to fetch info `{:#?}`", info)) } + #[cfg(not(feature = "disable-repo-management"))] Repo { cmd } => match cmd { RepoCommand::Add { uri } => { handler::repo_add::main(uri.clone())