summaryrefslogtreecommitdiffstats
path: root/libimagrt/src/runtime.rs
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 /libimagrt/src/runtime.rs
parenta6a7e43b39979a276243807ac7569ef04e13f9db (diff)
parentdc196793e9780e2319a620d3cc099b8b96c75bef (diff)
downloadimag-002c50a39e2a4e9426b0f8cc4bc7cc0d7ed8d599.tar.gz
imag-002c50a39e2a4e9426b0f8cc4bc7cc0d7ed8d599.tar.xz
Diffstat (limited to 'libimagrt/src/runtime.rs')
-rw-r--r--libimagrt/src/runtime.rs30
1 files changed, 28 insertions, 2 deletions
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
*/