Repository: mitsuhiko/rye
File: rye/src/cli/rye.rs (Rust)

Code before:
#[derive(Parser, Debug)]
pub struct CompletionCommand {
    /// The shell to generate a completion script for (defaults to 'bash').
    #[arg(short, long)]
    shell: Option<Shell>,
}

/// Performs an update of rye.
///
/// This can install updates from the latest release binaries or trigger a manual
/// compilation of Rye if Rust is installed.
#[derive(Parser, Debug)]
pub struct UpdateCommand {
    /// Update to a specific version.
    #[arg(long)]
    version: Option<String>,
    /// Update to a specific tag.
    #[arg(long)]
    tag: Option<String>,
    /// Update to a specific git rev.
    #[arg(long, conflicts_with = "tag")]
    rev: Option<String>,
    /// Update to a specific git branch.
    #[arg(long, conflicts_with = "tag", conflicts_with = "rev")]
    branch: Option<String>,
    /// Force reinstallation
    #[arg(long)]
    force: bool,
}

/// Triggers the initial installation of Rye.
///
/// This command is executed by the installation step to move Rye
/// to the intended target location and to add Rye to the environment
/// variables.
#[derive(Parser, Debug)]
pub struct InstallCommand {
    /// Skip prompts.
    #[arg(short, long)]
    yes: bool,
    /// Register a specific toolchain before bootstrap.
    #[arg(long)]
    toolchain: Option<PathBuf>,
    /// Use a specific toolchain version.
    #[arg(long)]
    toolchain_version: Option<PythonVersionRequest>,

    #[command(flatten)]
    mp: ModifyPath,
}


Review comment (suggestion):
I decided to just expand these rather than add an `unreachable!` but it's mostly personal preference.

Code after:
#[derive(Clone, Debug, ValueEnum)]
enum ShellCompletion {
    /// Bourne Again SHell (bash)
    Bash,
    /// Elvish shell
    Elvish,
    /// Friendly Interactive SHell (fish)
    Fish,
    /// PowerShell
    PowerShell,
    /// Z SHell (zsh)
    Zsh,
    /// Nushell
    Nushell,
}

impl Generator for ShellCompletion {
    /// Generate the file name for the completion script.
    fn file_name(&self, name: &str) -> String {
        match self {
            ShellCompletion::Nushell => Nushell.file_name(name),
            ShellCompletion::Bash => Shell::Bash.file_name(name),
            ShellCompletion::Elvish => Shell::Elvish.file_name(name),
            ShellCompletion::Fish => Shell::Fish.file_name(name),
            ShellCompletion::PowerShell => Shell::PowerShell.file_name(name),
            ShellCompletion::Zsh => Shell::Zsh.file_name(name),
        }
    }

    /// Generate the completion script for the shell.
    fn generate(&self, cmd: &clap::Command, buf: &mut dyn std::io::Write) {
        match self {
            ShellCompletion::Nushell => Nushell.generate(cmd, buf),
            ShellCompletion::Bash => Shell::Bash.generate(cmd, buf),
            ShellCompletion::Elvish => Shell::Elvish.generate(cmd, buf),
            ShellCompletion::Fish => Shell::Fish.generate(cmd, buf),
            ShellCompletion::PowerShell => Shell::PowerShell.generate(cmd, buf),
            ShellCompletion::Zsh => Shell::Zsh.generate(cmd, buf),
        }
    }
}

/// Generates a completion script for a shell.
#[derive(Parser, Debug)]
pub struct CompletionCommand {
    /// The shell to generate a completion script for (defaults to 'bash').
    #[arg(short, long)]
    shell: Option<ShellCompletion>,
}

/// Performs an update of rye.