diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2016-10-28 09:42:44 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2016-10-28 09:42:44 +0200 |
commit | 82e61db4f7551b50787811f49bb42d609e4ba704 (patch) | |
tree | daf1b278acc0d805520dc053d1e964f7019bb8cf /libimagrt | |
parent | 0404b24333f7f41cb6821fd11003260ec45799af (diff) |
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.
Diffstat (limited to 'libimagrt')
-rw-r--r-- | libimagrt/Cargo.toml | 2 | ||||
-rw-r--r-- | libimagrt/src/runtime.rs | 25 |
2 files changed, 26 insertions, 1 deletions
diff --git a/libimagrt/Cargo.toml b/libimagrt/Cargo.toml index d72d173b..ae38c350 100644 --- a/libimagrt/Cargo.toml +++ b/libimagrt/Cargo.toml @@ -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" diff --git a/libimagrt/src/runtime.rs b/libimagrt/src/runtime.rs index f85b274c..995f889a 100644 --- a/libimagrt/src/runtime.rs +++ b/libimagrt/src/runtime.rs @@ -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 */ |