Repository: starship/starship
File: src/main.rs (Rust)

Code before:
    subcommand_required=true,
    arg_required_else_help=true,
)]
struct Cli {
    #[clap(subcommand)]
    command: Commands,
}

#[derive(clap::Parser, ValueEnum, Debug, Clone, PartialEq, Eq)]
enum CompletionShell {
    Bash,
    Elvish,
    Fish,
    Nushell,
    PowerShell,
    Zsh,
}

fn generate_main_shell(shell: clap_complete::Shell) {
    generate(
        shell,
        &mut Cli::command(),
        "starship",
        &mut io::stdout().lock(),
    )
}
fn generate_nushell(shell: clap_complete_nushell::Nushell) {
    generate(
        shell,
        &mut Cli::command(),
        "starship",
        &mut io::stdout().lock(),
    )
}

fn generate_completions(shell: CompletionShell) {
    match shell {
        CompletionShell::Bash => generate_main_shell(clap_complete::Shell::Bash),
        CompletionShell::Elvish => generate_main_shell(clap_complete::Shell::Elvish),
        CompletionShell::Fish => generate_main_shell(clap_complete::Shell::Fish),
        CompletionShell::PowerShell => generate_main_shell(clap_complete::Shell::PowerShell),
        CompletionShell::Zsh => generate_main_shell(clap_complete::Shell::Zsh),
        CompletionShell::Nushell => generate_nushell(clap_complete_nushell::Nushell),
    }
}

#[derive(Subcommand, Debug)]
enum Commands {
    /// Create a pre-populated GitHub issue with information about your configuration
    BugReport,
    /// Generate starship shell completions for your shell to stdout

Review comment (suggestion):
These can share a single definition:
```suggestion
fn generate_main_shell(shell: impl clap_complete::Generator) {
    generate(
        shell,
        &mut Cli::command(),
        "starship",
        &mut io::stdout().lock(),
    )
}
```

Code after:
    subcommand_required=true,
    arg_required_else_help=true,
)]
struct Cli {
    #[clap(subcommand)]
    command: Commands,
}

#[derive(clap::Parser, ValueEnum, Debug, Clone, PartialEq, Eq)]
enum CompletionShell {
    Bash,
    Elvish,
    Fish,
    Nushell,
    PowerShell,
    Zsh,
}

fn generate_shell(shell: impl clap_complete::Generator) {
    generate(
        shell,
        &mut Cli::command(),
        "starship",
        &mut io::stdout().lock(),
    )
}

fn generate_completions(shell: CompletionShell) {
    match shell {
        CompletionShell::Bash => generate_shell(clap_complete::Shell::Bash),
        CompletionShell::Elvish => generate_shell(clap_complete::Shell::Elvish),
        CompletionShell::Fish => generate_shell(clap_complete::Shell::Fish),
        CompletionShell::PowerShell => generate_shell(clap_complete::Shell::PowerShell),
        CompletionShell::Zsh => generate_shell(clap_complete::Shell::Zsh),
        CompletionShell::Nushell => generate_shell(clap_complete_nushell::Nushell),
    }
}

#[derive(Subcommand, Debug)]
enum Commands {
    /// Create a pre-populated GitHub issue with information about your configuration
    BugReport,
    /// Generate starship shell completions for your shell to stdout
    Completions {
        #[clap(value_enum)]
        shell: CompletionShell,
    },
    /// Edit the starship configuration
    Config {
        /// Configuration key to edit
        #[clap(requires = "value")]