use anyhow::Result;
use clap::{self, App, Arg, ArgMatches, Shell, SubCommand};
use log::debug;
type OptionShell<'a> = Option<&'a str>;
pub enum Command<'a> {
Generate(OptionShell<'a>),
}
pub fn matches<'a>(m: &'a ArgMatches) -> Result<Option<Command<'a>>> {
if let Some(m) = m.subcommand_matches("completion") {
debug!("completion command matched");
let shell = m.value_of("shell");
debug!("shell: `{:?}`", shell);
return Ok(Some(Command::Generate(shell)));
};
Ok(None)
}
pub fn subcmds<'a>() -> Vec<App<'a, 'a>> {
vec![SubCommand::with_name("completion")
.aliases(&["completions", "compl", "compe", "comp"])
.about("Generates the completion script for the given shell")
.args(&[Arg::with_name("shell")
.possible_values(&Shell::variants()[..])
.required(true)])]
}