Skip to content

Commit 3fa7b8f

Browse files
authored
Merge pull request #4903 from CosmicHorrorDev/doc-generate-all-completions
doc(complete): Add an example generating all shell completions
2 parents 36f7928 + 863dd90 commit 3fa7b8f

File tree

1 file changed

+26
-0
lines changed
  • clap_complete/src/generator

1 file changed

+26
-0
lines changed

clap_complete/src/generator/mod.rs

+26
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,32 @@ pub trait Generator {
162162
///
163163
/// **NOTE:** Please look at the individual [shells][crate::shells]
164164
/// to see the name of the files generated.
165+
///
166+
/// Using [`ValueEnum::value_variants()`][clap::ValueEnum::value_variants] you can easily loop over
167+
/// all the supported shell variants to generate all the completions at once too.
168+
///
169+
/// ```ignore
170+
/// use clap::ValueEnum;
171+
/// use clap_complete::{generate_to, Shell};
172+
/// use std::env;
173+
/// use std::io::Error;
174+
///
175+
/// include!("src/cli.rs");
176+
///
177+
/// fn main() -> Result<(), Error> {
178+
/// let outdir = match env::var_os("OUT_DIR") {
179+
/// None => return Ok(()),
180+
/// Some(outdir) => outdir,
181+
/// };
182+
///
183+
/// let mut cmd = build_cli();
184+
/// for &shell in Shell::value_variants() {
185+
/// generate_to(shell, &mut cmd, "myapp", outdir)?;
186+
/// }
187+
///
188+
/// Ok(())
189+
/// }
190+
/// ```
165191
pub fn generate_to<G, S, T>(
166192
gen: G,
167193
cmd: &mut Command,

0 commit comments

Comments
 (0)