Repository: clap-rs/clap (language: rust)

Issue:
complete: Add `Shell` iterator
### Please complete the following tasks

- [X] I have searched the [discussions](https://github.com/clap-rs/clap/discussions)
- [X] I have searched the [open](https://github.com/clap-rs/clap/issues) and [rejected](https://github.com/clap-rs/clap/issues?q=is%3Aissue+label%3AS-wont-fix+is%3Aclosed) issues

### Clap Version

4.2.7

### Describe your use case

It would be nice to have an iterator over all `Shell`'s for generating all possible completions. It would allow for something like

```rust
for shell in Shell::iter() {
    let cmd = Opts::command();
    generate_to(shell, &mut cmd, "bin", &out_dir).unwrap();
}
```

### Describe the solution you'd like

Have an `::iter()` method on `Shell` that returns an iterator over all shell variants

### Alternatives, if applicable

_No response_

### Additional Context

_No response_


Discussion / hints:
#4901 demonstrates how this could be implemented, but I'm open to design discussions and other considerations
Do you need this since it implements `ValueEnum::value_variants`
I somehow totally missed that when looking over things. Yes that covers my use case!

Would you be open to me adding a new example or extending the existing one for `generate_to()`? It seems to be an appropriate place since the common case would be generating all possible completion files
> Would you be open to me adding a new example or extending the existing one for generate_to()? It seems to be an appropriate place since the common case would be generating all possible completion files

Sure

Fix patch:
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<G, S, T>(
     gen: G,
     cmd: &mut Command,


Test patch: