From 2107ff0617affa503fcb71eb18f3f31457693c2a Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Wed, 29 May 2024 23:57:39 -0400 Subject: [PATCH] Fix CLI deserialization of PowerShell (powershell) (#1125) Closes https://github.com/astral-sh/rye/issues/1124. --- rye/src/cli/rye.rs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/rye/src/cli/rye.rs b/rye/src/cli/rye.rs index ad5e2fcebd..b744bb0b7c 100644 --- a/rye/src/cli/rye.rs +++ b/rye/src/cli/rye.rs @@ -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; @@ -53,7 +54,7 @@ pub struct Args { command: SubCommand, } -#[derive(Clone, Debug, ValueEnum)] +#[derive(Clone, Debug)] enum ShellCompletion { /// Bourne Again SHell (bash) Bash, @@ -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 { + 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 {