Skip to content

Commit

Permalink
Fix CLI deserialization of PowerShell (powershell) (astral-sh#1125)
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed May 30, 2024
1 parent c14f2a7 commit 2107ff0
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion rye/src/cli/rye.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::sync::Arc;
use std::{env, fs};

use anyhow::{anyhow, bail, Context, Error};
use clap::builder::PossibleValue;
use clap::{CommandFactory, Parser, ValueEnum};
use clap_complete::{Generator, Shell};
use clap_complete_nushell::Nushell;
Expand Down Expand Up @@ -53,7 +54,7 @@ pub struct Args {
command: SubCommand,
}

#[derive(Clone, Debug, ValueEnum)]
#[derive(Clone, Debug)]
enum ShellCompletion {
/// Bourne Again SHell (bash)
Bash,
Expand All @@ -69,6 +70,32 @@ enum ShellCompletion {
Nushell,
}

impl ValueEnum for ShellCompletion {
/// Returns the variants for the shell completion.
fn value_variants<'a>() -> &'a [Self] {
&[
ShellCompletion::Bash,
ShellCompletion::Elvish,
ShellCompletion::Fish,
ShellCompletion::PowerShell,
ShellCompletion::Zsh,
ShellCompletion::Nushell,
]
}

/// Returns the possible value for the shell completion.
fn to_possible_value<'a>(&self) -> Option<PossibleValue> {
Some(match self {
ShellCompletion::Bash => PossibleValue::new("bash"),
ShellCompletion::Elvish => PossibleValue::new("elvish"),
ShellCompletion::Fish => PossibleValue::new("fish"),
ShellCompletion::PowerShell => PossibleValue::new("powershell"),
ShellCompletion::Zsh => PossibleValue::new("zsh"),
ShellCompletion::Nushell => PossibleValue::new("nushell"),
})
}
}

impl Generator for ShellCompletion {
/// Generate the file name for the completion script.
fn file_name(&self, name: &str) -> String {
Expand Down

0 comments on commit 2107ff0

Please sign in to comment.