summaryrefslogtreecommitdiffstats
path: root/libimagrt/src/runtime.rs
diff options
context:
space:
mode:
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
*/