From 82e61db4f7551b50787811f49bb42d609e4ba704 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 28 Oct 2016 09:42:44 +0200 Subject: 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. --- libimagrt/Cargo.toml | 2 +- libimagrt/src/runtime.rs | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) 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, 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::().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 */ -- cgit v1.2.3 From 39304db8bab7e34e9756f8971f7a4222affb1b37 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 31 Oct 2016 22:31:03 +0100 Subject: Clone App here so we can consume it elsewhere --- libimagrt/src/runtime.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libimagrt/src/runtime.rs b/libimagrt/src/runtime.rs index 995f889a..a1ff47a7 100644 --- a/libimagrt/src/runtime.rs +++ b/libimagrt/src/runtime.rs @@ -55,7 +55,7 @@ impl<'a> Runtime<'a> { * The cli_spec object should be initially build with the ::get_default_cli_builder() function. * */ - pub fn new(cli_spec: App<'a, 'a>) -> Result, RuntimeError> { + pub fn new(mut cli_spec: App<'a, 'a>) -> Result, RuntimeError> { use std::env; use std::io::stdout; @@ -74,7 +74,7 @@ impl<'a> Runtime<'a> { use configuration::error::ConfigErrorKind; - let matches = cli_spec.get_matches(); + let matches = cli_spec.clone().get_matches(); let is_debugging = matches.is_present("debugging"); let is_verbose = matches.is_present("verbosity"); -- cgit v1.2.3 From 17f42fd5e45784295bc56e18ade158ad5e6bcbf5 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 2 Nov 2016 13:20:52 +0100 Subject: Update clap to >=2.17 So we have `clap::App::get_name()`. --- imag-bookmark/Cargo.toml | 2 +- imag-counter/Cargo.toml | 2 +- imag-link/Cargo.toml | 2 +- imag-notes/Cargo.toml | 2 +- imag-ref/Cargo.toml | 2 +- imag-todo/Cargo.toml | 2 +- libimagentryfilter/Cargo.toml | 2 +- libimaginteraction/Cargo.toml | 2 +- libimagrt/Cargo.toml | 2 +- libimagtimeui/Cargo.toml | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/imag-bookmark/Cargo.toml b/imag-bookmark/Cargo.toml index 61970c3c..61b54528 100644 --- a/imag-bookmark/Cargo.toml +++ b/imag-bookmark/Cargo.toml @@ -14,7 +14,7 @@ repository = "https://github.com/matthiasbeyer/imag" homepage = "http://imag-pim.org" [dependencies] -clap = "2.*" +clap = ">=2.17" log = "0.3" version = "2.0.1" diff --git a/imag-counter/Cargo.toml b/imag-counter/Cargo.toml index 138cd5c3..016eadf5 100644 --- a/imag-counter/Cargo.toml +++ b/imag-counter/Cargo.toml @@ -14,7 +14,7 @@ repository = "https://github.com/matthiasbeyer/imag" homepage = "http://imag-pim.org" [dependencies] -clap = "2.*" +clap = ">=2.17" log = "0.3" version = "2.0.1" diff --git a/imag-link/Cargo.toml b/imag-link/Cargo.toml index d5153958..c40a7d3c 100644 --- a/imag-link/Cargo.toml +++ b/imag-link/Cargo.toml @@ -15,7 +15,7 @@ homepage = "http://imag-pim.org" [dependencies] semver = "0.5.1" -clap = "2.*" +clap = ">=2.17" log = "0.3" version = "2.0.1" toml = "0.2.*" diff --git a/imag-notes/Cargo.toml b/imag-notes/Cargo.toml index 0656c2e6..59f4a802 100644 --- a/imag-notes/Cargo.toml +++ b/imag-notes/Cargo.toml @@ -15,7 +15,7 @@ homepage = "http://imag-pim.org" [dependencies] semver = "0.2.1" -clap = "2.*" +clap = ">=2.17" log = "0.3" version = "2.0.1" itertools = "0.5" diff --git a/imag-ref/Cargo.toml b/imag-ref/Cargo.toml index c23cd63b..730d966f 100644 --- a/imag-ref/Cargo.toml +++ b/imag-ref/Cargo.toml @@ -15,7 +15,7 @@ homepage = "http://imag-pim.org" [dependencies] semver = "0.5.1" -clap = "2.*" +clap = ">=2.17" log = "0.3" version = "2.0.1" diff --git a/imag-todo/Cargo.toml b/imag-todo/Cargo.toml index 31993f0a..7a3cbbe9 100644 --- a/imag-todo/Cargo.toml +++ b/imag-todo/Cargo.toml @@ -14,7 +14,7 @@ repository = "https://github.com/matthiasbeyer/imag" homepage = "http://imag-pim.org" [dependencies] -clap = "2.*" +clap = ">=2.17" glob = "0.2.11" log = "0.3.6" semver = "0.5.1" diff --git a/libimagentryfilter/Cargo.toml b/libimagentryfilter/Cargo.toml index fd320a5f..fd5562ed 100644 --- a/libimagentryfilter/Cargo.toml +++ b/libimagentryfilter/Cargo.toml @@ -14,7 +14,7 @@ repository = "https://github.com/matthiasbeyer/imag" homepage = "http://imag-pim.org" [dependencies] -clap = "2.*" +clap = ">=2.17" filters = "0.1.*" itertools = "0.5" log = "0.3" diff --git a/libimaginteraction/Cargo.toml b/libimaginteraction/Cargo.toml index e6a4a2e7..cde39f26 100644 --- a/libimaginteraction/Cargo.toml +++ b/libimaginteraction/Cargo.toml @@ -15,7 +15,7 @@ homepage = "http://imag-pim.org" [dependencies] ansi_term = "0.9.*" -clap = "2.*" +clap = ">=2.17" interactor = "0.1" lazy_static = "0.2.*" log = "0.3" diff --git a/libimagrt/Cargo.toml b/libimagrt/Cargo.toml index ae38c350..8655bccd 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.16.1" +clap = ">=2.17" env_logger = "0.3" toml = "0.2.*" log = "0.3" diff --git a/libimagtimeui/Cargo.toml b/libimagtimeui/Cargo.toml index 8f07c241..32509fda 100644 --- a/libimagtimeui/Cargo.toml +++ b/libimagtimeui/Cargo.toml @@ -14,7 +14,7 @@ repository = "https://github.com/matthiasbeyer/imag" homepage = "http://imag-pim.org" [dependencies] -clap = "2.*" +clap = ">=2.17" lazy_static = "0.2" log = "0.3" chrono = "0.2" -- cgit v1.2.3 From dc196793e9780e2319a620d3cc099b8b96c75bef Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 2 Nov 2016 13:22:58 +0100 Subject: Pass real app name --- libimagrt/src/runtime.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libimagrt/src/runtime.rs b/libimagrt/src/runtime.rs index a1ff47a7..b821e66d 100644 --- a/libimagrt/src/runtime.rs +++ b/libimagrt/src/runtime.rs @@ -85,8 +85,9 @@ impl<'a> Runtime<'a> { match matches.value_of(Runtime::arg_generate_compl()) { Some(shell) => { debug!("Generating shell completion script, writing to stdout"); - let shell = shell.parse::().unwrap(); // clap has our back here. - cli_spec.gen_completions_to("fakename", shell, &mut stdout()); + let shell = shell.parse::().unwrap(); // clap has our back here. + let appname = String::from(cli_spec.get_name()); + cli_spec.gen_completions_to(appname, shell, &mut stdout()); }, _ => debug!("Not generating shell completion script"), } -- cgit v1.2.3