From b867464dd58baa75e8889d197d7ae6f5574bb198 Mon Sep 17 00:00:00 2001 From: Shaishav Gandhi Date: Sun, 26 Apr 2020 12:24:30 -0700 Subject: [PATCH] Add remaining completion files (#67) --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/cli.rs | 18 ++++++++++-------- src/main.rs | 35 +++++++++++++++++++++++++---------- 4 files changed, 37 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6b97c5a..eef4434 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -356,7 +356,7 @@ dependencies = [ [[package]] name = "fab" -version = "0.4.1" +version = "0.4.2" dependencies = [ "clap", "clap_generate", diff --git a/Cargo.toml b/Cargo.toml index bf2a65d..16a4422 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fab" -version = "0.4.1" +version = "0.4.2" authors = ["Shaishav Gandhi "] edition = "2018" diff --git a/src/cli.rs b/src/cli.rs index 657051a..3c7ac8f 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,7 +1,7 @@ use crate::preferences::Preferences; use clap::{App, Arg}; -pub const VERSION: &str = "0.4.1"; +pub const VERSION: &str = "0.4.2"; /// Builds the App with commands and defaults. pub fn build_cli(preferences: &Preferences) -> App { @@ -94,15 +94,17 @@ pub fn build_cli(preferences: &Preferences) -> App { .author("Shaishav "), ) .subcommand( - App::new("autocomplete") - .about("Add autocomplete suggestions for vim") - .version(VERSION) - .author("Shaishav "), - ) - .subcommand( - App::new("generate-bash-completions") + App::new("generate-shell-completions") .about("Generate the bash completion files for fab") .version(VERSION) + .arg( + Arg::with_name("shell") + .short('s') + .long("shell") + .required(true) + .help("Pass the shell for which you want completions") + .possible_values(&["bash", "zsh", "fish", "elvish", "powershell"]), + ) .author("Shaishav "), ) } diff --git a/src/main.rs b/src/main.rs index 3cb9a6d..708beea 100644 --- a/src/main.rs +++ b/src/main.rs @@ -37,16 +37,31 @@ fn main() -> Result<(), Error> { summary::process_summary(matches, &config, &preferences)?; } else if let Some(matches) = matches.subcommand_matches("configure") { preferences::process_configuration(matches)?; - } else if let Some(_matches) = matches.subcommand_matches("generate-bash-completions") { - generate::(&mut cli::build_cli(&preferences), "fab", &mut io::stdout()); - } else if let Some(_matches) = matches.subcommand_matches("generate-zsh-completions") { - generate::(&mut cli::build_cli(&preferences), "fab", &mut io::stdout()); - } else if let Some(_matches) = matches.subcommand_matches("generate-fish-completions") { - generate::(&mut cli::build_cli(&preferences), "fab", &mut io::stdout()); - } else if let Some(_matches) = matches.subcommand_matches("generate-elvish-completions") { - generate::(&mut cli::build_cli(&preferences), "fab", &mut io::stdout()); - } else if let Some(_matches) = matches.subcommand_matches("generate-powershell-completions") { - generate::(&mut cli::build_cli(&preferences), "fab", &mut io::stdout()); + } else if let Some(matches) = matches.subcommand_matches("generate-shell-completions") { + let shell = matches + .value_of("shell") + .expect("No shell specified for generating completions"); + + match shell { + "bash" => { + generate::(&mut cli::build_cli(&preferences), "fab", &mut io::stdout()) + } + "zsh" => { + generate::(&mut cli::build_cli(&preferences), "fab", &mut io::stdout()) + } + "fish" => { + generate::(&mut cli::build_cli(&preferences), "fab", &mut io::stdout()) + } + "elvish" => { + generate::(&mut cli::build_cli(&preferences), "fab", &mut io::stdout()) + } + "powershell" => generate::( + &mut cli::build_cli(&preferences), + "fab", + &mut io::stdout(), + ), + _ => return Err(failure::err_msg("No matching shell specified")), + } } Ok(()) }