From 863dd90ca4d06952c4f9451195215a34db7dbedd Mon Sep 17 00:00:00 2001 From: Cosmic Horror Date: Sat, 13 May 2023 11:25:55 -0600 Subject: [PATCH] docs(complete): Demo generating all completions --- clap_complete/src/generator/mod.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/clap_complete/src/generator/mod.rs b/clap_complete/src/generator/mod.rs index c6e5c5ec81d..a371f68a650 100644 --- a/clap_complete/src/generator/mod.rs +++ b/clap_complete/src/generator/mod.rs @@ -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( gen: G, cmd: &mut Command,