summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2016-11-05 13:22:55 +0100
committerGitHub <noreply@github.com>2016-11-05 13:22:55 +0100
commit002c50a39e2a4e9426b0f8cc4bc7cc0d7ed8d599 (patch)
tree89e69422eb01e3fb35ff10cdf54c01d8ce4d9b47
parenta6a7e43b39979a276243807ac7569ef04e13f9db (diff)
parentdc196793e9780e2319a620d3cc099b8b96c75bef (diff)
Merge pull request #826 from matthiasbeyer/clap-completion
Bake in shell-compl generation
-rw-r--r--imag-bookmark/Cargo.toml2
-rw-r--r--imag-counter/Cargo.toml2
-rw-r--r--imag-link/Cargo.toml2
-rw-r--r--imag-notes/Cargo.toml2
-rw-r--r--imag-ref/Cargo.toml2
-rw-r--r--imag-todo/Cargo.toml2
-rw-r--r--libimagentryfilter/Cargo.toml2
-rw-r--r--libimaginteraction/Cargo.toml2
-rw-r--r--libimagrt/Cargo.toml2
-rw-r--r--libimagrt/src/runtime.rs30
-rw-r--r--libimagtimeui/Cargo.toml2
11 files changed, 38 insertions, 12 deletions
diff --git a/imag-bookmark/Cargo.toml b/imag-bookmark/Cargo.toml
index 3d3a18cf..c1b4e55c 100644
--- a/imag-bookmark/Cargo.toml
+++ b/imag-bookmark/Cargo.toml
@@ -17,7 +17,7 @@ homepage = "http://imag-pim.org"
codegen-units = 2
[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 1c7968b7..80fdedad 100644
--- a/imag-counter/Cargo.toml
+++ b/imag-counter/Cargo.toml
@@ -17,7 +17,7 @@ homepage = "http://imag-pim.org"
codegen-units = 2
[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 bb5ad615..ffe57ed5 100644
--- a/imag-link/Cargo.toml
+++ b/imag-link/Cargo.toml
@@ -18,7 +18,7 @@ codegen-units = 2
[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 39ec0f71..c7ef71a3 100644
--- a/imag-notes/Cargo.toml
+++ b/imag-notes/Cargo.toml
@@ -18,7 +18,7 @@ codegen-units = 2
[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 1e5fb9e6..eae86734 100644
--- a/imag-ref/Cargo.toml
+++ b/imag-ref/Cargo.toml
@@ -18,7 +18,7 @@ codegen-units = 2
[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 320cfea4..bb75c577 100644
--- a/imag-todo/Cargo.toml
+++ b/imag-todo/Cargo.toml
@@ -17,7 +17,7 @@ homepage = "http://imag-pim.org"
codegen-units = 2
[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 6f090335..8fc6f6f7 100644
--- a/libimagentryfilter/Cargo.toml
+++ b/libimagentryfilter/Cargo.toml
@@ -17,7 +17,7 @@ homepage = "http://imag-pim.org"
codegen-units = 2
[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 044fe9b0..e9333af3 100644
--- a/libimaginteraction/Cargo.toml
+++ b/libimaginteraction/Cargo.toml
@@ -18,7 +18,7 @@ codegen-units = 2
[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 129362d0..68f24208 100644
--- a/libimagrt/Cargo.toml
+++ b/libimagrt/Cargo.toml
@@ -17,7 +17,7 @@ homepage = "http://imag-pim.org"
codegen-units = 2
[dependencies]
-clap = "2.*"
+clap = ">=2.17"
env_logger = "0.3"
toml = "0.2.*"
log = "0.3"
diff --git a/libimagrt/src/runtime.rs b/libimagrt/src/runtime.rs
index f85b274c..b821e66d 100644
--- a/libimagrt/src/runtime.rs
+++ b/libimagrt/src/runtime.rs
@@ -55,8 +55,11 @@ 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<Runtime<'a>, RuntimeError> {
+ pub fn new(mut 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;
@@ -71,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");
@@ -79,6 +82,16 @@ 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.
+ let appname = String::from(cli_spec.get_name());
+ cli_spec.gen_completions_to(appname, shell, &mut stdout());
+ },
+ _ => debug!("Not generating shell completion script"),
+ }
+
let rtp : PathBuf = matches.value_of("runtimepath")
.map_or_else(|| {
env::var("HOME")
@@ -255,6 +268,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 +324,10 @@ impl<'a> Runtime<'a> {
"editor"
}
+ pub fn arg_generate_compl() -> &'static str {
+ "generate-completion"
+ }
+
/**
* Initialize the internal logger
*/
diff --git a/libimagtimeui/Cargo.toml b/libimagtimeui/Cargo.toml
index b59a16a0..fcf5686e 100644
--- a/libimagtimeui/Cargo.toml
+++ b/libimagtimeui/Cargo.toml
@@ -17,7 +17,7 @@ homepage = "http://imag-pim.org"
codegen-units = 2
[dependencies]
-clap = "2.*"
+clap = ">=2.17"
lazy_static = "0.2"
log = "0.3"
chrono = "0.2"