Skip to content

Commit 2379455

Browse files
committed
clean up completions shell types for clap parsing
1 parent c8dae3e commit 2379455

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

src/command.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,28 @@ pub enum Commands {
108108
/// Generate shell completions
109109
Completions {
110110
/// Shell to generate completions for
111-
#[arg(value_parser = ["bash", "zsh", "fish"])]
112-
shell: String,
111+
#[arg(value_enum)]
112+
shell: ShellChoice,
113113
},
114114
}
115115

116+
#[derive(Clone, clap::ValueEnum)]
117+
pub enum ShellChoice {
118+
Bash,
119+
Zsh,
120+
Fish,
121+
}
122+
123+
impl From<ShellChoice> for clap_complete::Shell {
124+
fn from(s: ShellChoice) -> Self {
125+
match s {
126+
ShellChoice::Bash => clap_complete::Shell::Bash,
127+
ShellChoice::Zsh => clap_complete::Shell::Zsh,
128+
ShellChoice::Fish => clap_complete::Shell::Fish,
129+
}
130+
}
131+
}
132+
116133
#[derive(Subcommand)]
117134
pub enum AuthCommands {
118135
/// Remove authentication for a profile

src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ fn main() {
197197
}
198198
Commands::Completions { shell } => {
199199
use clap::CommandFactory;
200-
use clap_complete::{Shell, generate};
201-
let shell: Shell = shell.parse().unwrap();
200+
use clap_complete::generate;
201+
let shell: clap_complete::Shell = shell.into();
202202
let mut cmd = Cli::command();
203203
generate(shell, &mut cmd, "hotdata", &mut std::io::stdout());
204204
}

0 commit comments

Comments
 (0)