Skip to content

Commit

Permalink
Merge pull request #4903 from CosmicHorrorDev/doc-generate-all-comple…
Browse files Browse the repository at this point in the history
…tions

doc(complete): Add an example generating all shell completions
  • Loading branch information
epage committed May 13, 2023
2 parents 36f7928 + 863dd90 commit 3fa7b8f
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions clap_complete/src/generator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,32 @@ pub trait Generator {
///
/// **NOTE:** Please look at the individual [shells][crate::shells]
/// to see the name of the files generated.
///
/// Using [`ValueEnum::value_variants()`][clap::ValueEnum::value_variants] you can easily loop over
/// all the supported shell variants to generate all the completions at once too.
///
/// ```ignore
/// use clap::ValueEnum;
/// use clap_complete::{generate_to, Shell};
/// use std::env;
/// use std::io::Error;
///
/// include!("src/cli.rs");
///
/// fn main() -> Result<(), Error> {
/// let outdir = match env::var_os("OUT_DIR") {
/// None => return Ok(()),
/// Some(outdir) => outdir,
/// };
///
/// let mut cmd = build_cli();
/// for &shell in Shell::value_variants() {
/// generate_to(shell, &mut cmd, "myapp", outdir)?;
/// }
///
/// Ok(())
/// }
/// ```
pub fn generate_to<G, S, T>(
gen: G,
cmd: &mut Command,
Expand Down

0 comments on commit 3fa7b8f

Please sign in to comment.