add completion subcommands (#99)

* add completion subcommands

* improve error mgmt, add entry to readme

Co-authored-by: Clément DOUIN <soywod@users.noreply.github.com>
This commit is contained in:
remche
2021-04-14 10:28:23 +02:00
committed by GitHub
parent 8a617c314e
commit 9287846aed
3 changed files with 78 additions and 4 deletions
+34
View File
@@ -0,0 +1,34 @@
use clap::{self, App, ArgMatches, SubCommand};
use error_chain::error_chain;
use std::io;
error_chain! {}
pub fn completion_subcmds<'a>() -> Vec<App<'a, 'a>> {
vec![
SubCommand::with_name("bash-completions").about("Generates bash completions script"),
SubCommand::with_name("zsh-completions").about("Generates zsh completions script"),
SubCommand::with_name("fish-completions").about("Generates fish completions script"),
]
}
pub fn completion_matches(mut app: App, matches: &ArgMatches) -> Result<bool> {
use clap::Shell::*;
if matches.is_present("bash-completions") {
app.gen_completions_to("himalaya", Bash, &mut io::stdout());
return Ok(true);
}
if matches.is_present("zsh-completions") {
app.gen_completions_to("himalaya", Zsh, &mut io::stdout());
return Ok(true);
}
if matches.is_present("fish-completions") {
app.gen_completions_to("himalaya", Fish, &mut io::stdout());
return Ok(true);
}
Ok(false)
}