From dc0db358abe19481e475e10c32149b53370f1a1c Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 30 May 2024 05:57:31 +0200 Subject: Merging upstream version 1.72.1+dfsg1. Signed-off-by: Daniel Baumann --- vendor/clap_complete/src/generator/mod.rs | 26 ++++++++++++++++++++++++++ vendor/clap_complete/src/shells/zsh.rs | 4 +++- 2 files changed, 29 insertions(+), 1 deletion(-) (limited to 'vendor/clap_complete/src') diff --git a/vendor/clap_complete/src/generator/mod.rs b/vendor/clap_complete/src/generator/mod.rs index c6e5c5ec8..a371f68a6 100644 --- a/vendor/clap_complete/src/generator/mod.rs +++ b/vendor/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, diff --git a/vendor/clap_complete/src/shells/zsh.rs b/vendor/clap_complete/src/shells/zsh.rs index 71c586d8e..65d7af65b 100644 --- a/vendor/clap_complete/src/shells/zsh.rs +++ b/vendor/clap_complete/src/shells/zsh.rs @@ -624,7 +624,9 @@ fn write_positionals_of(p: &Command) -> String { } let cardinality_value; - let cardinality = if is_multi_valued { + // If we have any subcommands, we'll emit a catch-all argument, so we shouldn't + // emit one here. + let cardinality = if is_multi_valued && !p.has_subcommands() { match arg.get_value_terminator() { Some(terminator) => { cardinality_value = format!("*{}:", escape_value(terminator)); -- cgit v1.2.3