From 8d632b2b46d392ebdf12e22aff37f6aa2be3e764 Mon Sep 17 00:00:00 2001 From: Mikko Date: Wed, 3 Jul 2024 18:43:41 +0300 Subject: [PATCH] use strongly typed Shell type for completions subcommand argument (#978) --- src/bin/juliaup.rs | 2 +- src/cli.rs | 2 +- src/command_completions.rs | 20 +++++++------------- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/bin/juliaup.rs b/src/bin/juliaup.rs index 37fcca95..886e041d 100644 --- a/src/bin/juliaup.rs +++ b/src/bin/juliaup.rs @@ -110,6 +110,6 @@ fn main() -> Result<()> { #[cfg(not(feature = "selfupdate"))] SelfSubCmd::Uninstall {} => run_command_selfuninstall_unavailable(), }, - Juliaup::Completions { shell } => run_command_completions(&shell), + Juliaup::Completions { shell } => run_command_completions(shell), } } diff --git a/src/cli.rs b/src/cli.rs index f288ce86..14588c55 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -48,7 +48,7 @@ pub enum Juliaup { #[clap(subcommand, name = "self")] SelfSubCmd(SelfSubCmd), /// Generate tab-completion scripts for your shell - Completions { shell: String }, + Completions { shell: clap_complete::Shell }, // This is used for the cron jobs that we create. By using this UUID for the command // We can identify the cron jobs that were created by juliaup for uninstall purposes #[cfg(feature = "selfupdate")] diff --git a/src/command_completions.rs b/src/command_completions.rs index 291ee04a..b24627b8 100644 --- a/src/command_completions.rs +++ b/src/command_completions.rs @@ -1,22 +1,16 @@ use crate::cli; -use anyhow::bail; use anyhow::Result; use clap::CommandFactory; use clap_complete::Shell; use cli::Juliaup; use std::io; -use std::str::FromStr; -pub fn run_command_completions(shell: &str) -> Result<()> { - if let Ok(shell) = Shell::from_str(shell) { - clap_complete::generate( - shell, - &mut Juliaup::command(), - "juliaup", - &mut io::stdout().lock(), - ); - } else { - bail!("'{}' is not a supported shell.", shell) - } +pub fn run_command_completions(shell: Shell) -> Result<()> { + clap_complete::generate( + shell, + &mut Juliaup::command(), + "juliaup", + &mut io::stdout().lock(), + ); Ok(()) }