Skip to content

Commit

Permalink
boulder/cli: Add --generate-completions arg to generate bash/fish/z…
Browse files Browse the repository at this point in the history
…sh compl

Signed-off-by: Ikey Doherty <[email protected]>
  • Loading branch information
ikeycode committed Nov 6, 2024
1 parent 0e5537e commit d5e5a72
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions boulder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ yaml = { path = "../crates/yaml" }

chrono.workspace = true
clap.workspace = true
clap_complete.workspace = true
clap_mangen.workspace = true
derive_more.workspace = true
dirs.workspace = true
Expand Down
17 changes: 16 additions & 1 deletion boulder/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ use std::path::PathBuf;

use boulder::{env, Env};
use clap::{Args, CommandFactory, Parser};
use clap_complete::{
generate_to,
shells::{Bash, Fish, Zsh},
};
use clap_mangen::Man;
use std::fs::{self, File};
use thiserror::Error;
Expand Down Expand Up @@ -41,8 +45,10 @@ pub struct Global {
pub data_dir: Option<PathBuf>,
#[arg(long, global = true)]
pub moss_root: Option<PathBuf>,
#[arg(long, global = true)]
#[arg(long, global = true, hide = true)]
pub generate_manpages: Option<PathBuf>,
#[arg(long, global = true, hide = true)]
pub generate_completions: Option<PathBuf>,
}

#[derive(Debug, clap::Subcommand)]
Expand Down Expand Up @@ -84,6 +90,15 @@ pub fn process() -> Result<(), Error> {
return Ok(());
}

if let Some(dir) = global.generate_completions {
fs::create_dir_all(&dir)?;
let mut cmd = Command::command();
generate_to(Bash, &mut cmd, "boulder", &dir)?;
generate_to(Fish, &mut cmd, "boulder", &dir)?;
generate_to(Zsh, &mut cmd, "boulder", &dir)?;
return Ok(());
}

let env = Env::new(global.cache_dir, global.config_dir, global.data_dir, global.moss_root)?;

if global.verbose {
Expand Down

0 comments on commit d5e5a72

Please sign in to comment.