diff --git a/src/commands/repo/add.rs b/src/commands/repo/add.rs index 0c00a75..01a1d5b 100644 --- a/src/commands/repo/add.rs +++ b/src/commands/repo/add.rs @@ -25,10 +25,10 @@ fn ask_if_should_import_all(finder: &FinderChoice) -> Result { Ok(response.to_lowercase().starts_with('y')) } -pub fn main(uri: String) -> Result<()> { +pub fn main(uri: String, import_all: bool) -> Result<()> { let finder = CONFIG.finder(); - let should_import_all = ask_if_should_import_all(&finder).unwrap_or(false); + let should_import_all = import_all || ask_if_should_import_all(&finder).unwrap_or(false); let (actual_uri, user, repo) = git::meta(uri.as_str()); let cheat_pathbuf = filesystem::default_cheat_pathbuf()?; diff --git a/src/commands/repo/mod.rs b/src/commands/repo/mod.rs index be5dd25..b0d0c84 100644 --- a/src/commands/repo/mod.rs +++ b/src/commands/repo/mod.rs @@ -11,9 +11,16 @@ pub enum RepoCommand { Add { /// A URI to a git repository containing .cheat files ("user/repo" will download cheats from github.com/user/repo) uri: String, + /// Import all cheatsheets from repo without prompting + #[clap(short = 'a', long, visible_short_alias = 'y', visible_alias = "yes")] + all: bool, }, /// Browses for featured cheatsheet repos - Browse, + Browse { + /// Import all cheatsheets from selected repo without prompting + #[clap(short = 'a', long, visible_short_alias = 'y', visible_alias = "yes")] + all: bool, + }, } #[derive(Debug, Clone, Args)] @@ -25,14 +32,14 @@ pub struct Input { impl Runnable for Input { fn run(&self) -> Result<()> { match &self.cmd { - RepoCommand::Add { uri } => { - add::main(uri.clone()) + RepoCommand::Add { uri, all } => { + add::main(uri.clone(), *all) .with_context(|| format!("Failed to import cheatsheets from `{uri}`"))?; commands::core::main() } - RepoCommand::Browse => { + RepoCommand::Browse { all } => { let repo = browse::main().context("Failed to browse featured cheatsheets")?; - add::main(repo.clone()) + add::main(repo.clone(), *all) .with_context(|| format!("Failed to import cheatsheets from `{repo}`"))?; commands::core::main() }