Bake in shell-compl generation

Therefor we need to have at least clap 2.16.1.

We bake this into libimagrt::runtime::Runtime, so all binary crates
should automatically have it.
This commit is contained in:
Matthias Beyer 2016-10-28 09:42:44 +02:00
parent 0404b24333
commit 82e61db4f7
2 changed files with 26 additions and 1 deletions

View File

@ -14,7 +14,7 @@ repository = "https://github.com/matthiasbeyer/imag"
homepage = "http://imag-pim.org"
[dependencies]
clap = "2.*"
clap = ">=2.16.1"
env_logger = "0.3"
toml = "0.2.*"
log = "0.3"

View File

@ -57,6 +57,9 @@ impl<'a> Runtime<'a> {
*/
pub fn new(cli_spec: App<'a, 'a>) -> Result<Runtime<'a>, RuntimeError> {
use std::env;
use std::io::stdout;
use clap::Shell;
use libimagstore::hook::position::HookPosition as HP;
use libimagstore::hook::Hook;
@ -79,6 +82,15 @@ impl<'a> Runtime<'a> {
Runtime::init_logger(is_debugging, is_verbose, colored);
match matches.value_of(Runtime::arg_generate_compl()) {
Some(shell) => {
debug!("Generating shell completion script, writing to stdout");
let shell = shell.parse::<Shell>().unwrap(); // clap has our back here.
cli_spec.gen_completions_to("fakename", shell, &mut stdout());
},
_ => debug!("Not generating shell completion script"),
}
let rtp : PathBuf = matches.value_of("runtimepath")
.map_or_else(|| {
env::var("HOME")
@ -255,6 +267,15 @@ impl<'a> Runtime<'a> {
.help("Set editor")
.required(false)
.takes_value(true))
.arg(Arg::with_name(Runtime::arg_generate_compl())
.long("generate-commandline-completion")
.help("Generate the commandline completion for bash or zsh or fish")
.required(false)
.takes_value(true)
.value_name("SHELL")
.possible_values(&["bash", "fish", "zsh"]))
}
pub fn arg_names() -> Vec<&'static str> {
@ -302,6 +323,10 @@ impl<'a> Runtime<'a> {
"editor"
}
pub fn arg_generate_compl() -> &'static str {
"generate-completion"
}
/**
* Initialize the internal logger
*/