mirror of
https://github.com/pimalaya/himalaya.git
synced 2026-06-17 13:17:55 +08:00
9287846aed
* add completion subcommands * improve error mgmt, add entry to readme Co-authored-by: Clément DOUIN <soywod@users.noreply.github.com>
35 lines
1.0 KiB
Rust
35 lines
1.0 KiB
Rust
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)
|
|
}
|