Merge pull request #826 from matthiasbeyer/clap-completion
Bake in shell-compl generation
This commit is contained in:
commit
002c50a39e
11 changed files with 38 additions and 12 deletions
|
@ -17,7 +17,7 @@ homepage = "http://imag-pim.org"
|
||||||
codegen-units = 2
|
codegen-units = 2
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = "2.*"
|
clap = ">=2.17"
|
||||||
log = "0.3"
|
log = "0.3"
|
||||||
version = "2.0.1"
|
version = "2.0.1"
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ homepage = "http://imag-pim.org"
|
||||||
codegen-units = 2
|
codegen-units = 2
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = "2.*"
|
clap = ">=2.17"
|
||||||
log = "0.3"
|
log = "0.3"
|
||||||
version = "2.0.1"
|
version = "2.0.1"
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ codegen-units = 2
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
semver = "0.5.1"
|
semver = "0.5.1"
|
||||||
clap = "2.*"
|
clap = ">=2.17"
|
||||||
log = "0.3"
|
log = "0.3"
|
||||||
version = "2.0.1"
|
version = "2.0.1"
|
||||||
toml = "0.2.*"
|
toml = "0.2.*"
|
||||||
|
|
|
@ -18,7 +18,7 @@ codegen-units = 2
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
semver = "0.2.1"
|
semver = "0.2.1"
|
||||||
clap = "2.*"
|
clap = ">=2.17"
|
||||||
log = "0.3"
|
log = "0.3"
|
||||||
version = "2.0.1"
|
version = "2.0.1"
|
||||||
itertools = "0.5"
|
itertools = "0.5"
|
||||||
|
|
|
@ -18,7 +18,7 @@ codegen-units = 2
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
semver = "0.5.1"
|
semver = "0.5.1"
|
||||||
clap = "2.*"
|
clap = ">=2.17"
|
||||||
log = "0.3"
|
log = "0.3"
|
||||||
version = "2.0.1"
|
version = "2.0.1"
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ homepage = "http://imag-pim.org"
|
||||||
codegen-units = 2
|
codegen-units = 2
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = "2.*"
|
clap = ">=2.17"
|
||||||
glob = "0.2.11"
|
glob = "0.2.11"
|
||||||
log = "0.3.6"
|
log = "0.3.6"
|
||||||
semver = "0.5.1"
|
semver = "0.5.1"
|
||||||
|
|
|
@ -17,7 +17,7 @@ homepage = "http://imag-pim.org"
|
||||||
codegen-units = 2
|
codegen-units = 2
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = "2.*"
|
clap = ">=2.17"
|
||||||
filters = "0.1.*"
|
filters = "0.1.*"
|
||||||
itertools = "0.5"
|
itertools = "0.5"
|
||||||
log = "0.3"
|
log = "0.3"
|
||||||
|
|
|
@ -18,7 +18,7 @@ codegen-units = 2
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ansi_term = "0.9.*"
|
ansi_term = "0.9.*"
|
||||||
clap = "2.*"
|
clap = ">=2.17"
|
||||||
interactor = "0.1"
|
interactor = "0.1"
|
||||||
lazy_static = "0.2.*"
|
lazy_static = "0.2.*"
|
||||||
log = "0.3"
|
log = "0.3"
|
||||||
|
|
|
@ -17,7 +17,7 @@ homepage = "http://imag-pim.org"
|
||||||
codegen-units = 2
|
codegen-units = 2
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = "2.*"
|
clap = ">=2.17"
|
||||||
env_logger = "0.3"
|
env_logger = "0.3"
|
||||||
toml = "0.2.*"
|
toml = "0.2.*"
|
||||||
log = "0.3"
|
log = "0.3"
|
||||||
|
|
|
@ -55,8 +55,11 @@ impl<'a> Runtime<'a> {
|
||||||
* The cli_spec object should be initially build with the ::get_default_cli_builder() function.
|
* 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::env;
|
||||||
|
use std::io::stdout;
|
||||||
|
|
||||||
|
use clap::Shell;
|
||||||
|
|
||||||
use libimagstore::hook::position::HookPosition as HP;
|
use libimagstore::hook::position::HookPosition as HP;
|
||||||
use libimagstore::hook::Hook;
|
use libimagstore::hook::Hook;
|
||||||
|
@ -71,7 +74,7 @@ impl<'a> Runtime<'a> {
|
||||||
|
|
||||||
use configuration::error::ConfigErrorKind;
|
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_debugging = matches.is_present("debugging");
|
||||||
let is_verbose = matches.is_present("verbosity");
|
let is_verbose = matches.is_present("verbosity");
|
||||||
|
@ -79,6 +82,16 @@ impl<'a> Runtime<'a> {
|
||||||
|
|
||||||
Runtime::init_logger(is_debugging, is_verbose, colored);
|
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")
|
let rtp : PathBuf = matches.value_of("runtimepath")
|
||||||
.map_or_else(|| {
|
.map_or_else(|| {
|
||||||
env::var("HOME")
|
env::var("HOME")
|
||||||
|
@ -255,6 +268,15 @@ impl<'a> Runtime<'a> {
|
||||||
.help("Set editor")
|
.help("Set editor")
|
||||||
.required(false)
|
.required(false)
|
||||||
.takes_value(true))
|
.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> {
|
pub fn arg_names() -> Vec<&'static str> {
|
||||||
|
@ -302,6 +324,10 @@ impl<'a> Runtime<'a> {
|
||||||
"editor"
|
"editor"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn arg_generate_compl() -> &'static str {
|
||||||
|
"generate-completion"
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the internal logger
|
* Initialize the internal logger
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -17,7 +17,7 @@ homepage = "http://imag-pim.org"
|
||||||
codegen-units = 2
|
codegen-units = 2
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = "2.*"
|
clap = ">=2.17"
|
||||||
lazy_static = "0.2"
|
lazy_static = "0.2"
|
||||||
log = "0.3"
|
log = "0.3"
|
||||||
chrono = "0.2"
|
chrono = "0.2"
|
||||||
|
|
Loading…
Reference in a new issue