summaryrefslogtreecommitdiffstats
path: root/lib/core/libimagrt
diff options
context:
space:
mode:
Diffstat (limited to 'lib/core/libimagrt')
-rw-r--r--lib/core/libimagrt/Cargo.toml4
-rw-r--r--lib/core/libimagrt/src/logger.rs10
-rw-r--r--lib/core/libimagrt/src/runtime.rs69
3 files changed, 24 insertions, 59 deletions
diff --git a/lib/core/libimagrt/Cargo.toml b/lib/core/libimagrt/Cargo.toml
index 8e90d8a0..3400f314 100644
--- a/lib/core/libimagrt/Cargo.toml
+++ b/lib/core/libimagrt/Cargo.toml
@@ -37,9 +37,9 @@ libimagutil = { version = "0.7.0", path = "../../../lib/etc/libimagutil"
libimaginteraction = { version = "0.7.0", path = "../../../lib/etc/libimaginteraction" }
[dependencies.clap]
-version = ">=2.29"
+version = "^2.29"
default-features = false
-features = ["suggestions", "color"]
+features = ["suggestions", "color", "wrap_help"]
[dependencies.log]
version = "0.4.0-rc.1"
diff --git a/lib/core/libimagrt/src/logger.rs b/lib/core/libimagrt/src/logger.rs
index ec00a2e3..8d5d2e4d 100644
--- a/lib/core/libimagrt/src/logger.rs
+++ b/lib/core/libimagrt/src/logger.rs
@@ -231,13 +231,13 @@ fn aggregate_global_loglevel(matches: &ArgMatches, config: Option<&Value>) -> Re
return Ok(Some(Level::Debug))
}
- if matches.is_present(Runtime::arg_verbosity_name()) {
- return Ok(Some(Level::Info))
- }
-
match matches.value_of(Runtime::arg_verbosity_name()) {
Some(v) => match_log_level_str(v).map(Some),
- None => Ok(None),
+ None => if matches.is_present(Runtime::arg_verbosity_name()) {
+ Ok(Some(Level::Info))
+ } else {
+ Ok(None)
+ },
}
}
diff --git a/lib/core/libimagrt/src/runtime.rs b/lib/core/libimagrt/src/runtime.rs
index 07b24bd4..40ffac22 100644
--- a/lib/core/libimagrt/src/runtime.rs
+++ b/lib/core/libimagrt/src/runtime.rs
@@ -52,7 +52,6 @@ pub struct Runtime<'a> {
configuration: Option<Value>,
cli_matches: ArgMatches<'a>,
store: Store,
- use_pipe_magic: bool,
stdin_is_tty: bool,
stdout_is_tty: bool,
}
@@ -111,27 +110,14 @@ impl<'a> Runtime<'a> {
Runtime::_new(cli_app, matches, config)
}
- fn _new<C>(mut cli_app: C, matches: ArgMatches<'a>, config: Option<Value>)
+ fn _new<C>(cli_app: C, matches: ArgMatches<'a>, config: Option<Value>)
-> Result<Runtime<'a>, RuntimeError>
where C: Clone + CliSpec<'a> + InternalConfiguration
{
- use std::io::stdout;
- use clap::Shell;
-
if cli_app.enable_logging() {
Runtime::init_logger(&matches, config.as_ref())
}
- 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_app.name());
- cli_app.completions(appname, shell, &mut stdout());
- },
- _ => debug!("Not generating shell completion script"),
- }
-
let rtp = get_rtp_match(&matches);
let storepath = matches.value_of(Runtime::arg_storepath_name())
@@ -152,15 +138,12 @@ impl<'a> Runtime<'a> {
Store::new(storepath, &config)
};
- let pipe_magic = matches.is_present(Runtime::pipe_magic_name());
-
store_result.map(|store| {
Runtime {
cli_matches: matches,
configuration: config,
rtp: rtp,
store: store,
- use_pipe_magic: pipe_magic,
stdout_is_tty: ::atty::is(::atty::Stream::Stdout),
stdin_is_tty: ::atty::is(::atty::Stream::Stdin),
}
@@ -198,6 +181,7 @@ impl<'a> Runtime<'a> {
.required(false)
.takes_value(true)
.possible_values(&["trace", "debug", "info", "warn", "error"])
+ .default_value("info")
.value_name("LOGLEVEL"))
.arg(Arg::with_name(Runtime::arg_debugging_name())
@@ -242,14 +226,6 @@ impl<'a> Runtime<'a> {
.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"]))
-
.arg(Arg::with_name(Runtime::arg_logdest_name())
.long(Runtime::arg_logdest_name())
.help("Override the logging destinations from the configuration: values can be seperated by ',', a value of '-' marks the stderr output, everything else is expected to be a path")
@@ -257,13 +233,6 @@ impl<'a> Runtime<'a> {
.takes_value(true)
.value_name("LOGDESTS"))
- .arg(Arg::with_name(Runtime::pipe_magic_name())
- .long(Runtime::pipe_magic_name())
- .short("P")
- .help("Use pipe-detection. With this flag, imag expects a JSON store on STDIN if stdin is not a TTY and prints the store to STDOUT if it is not a TTY.")
- .required(false)
- .takes_value(false))
-
}
/// Get the argument names of the Runtime which are available
@@ -320,11 +289,6 @@ impl<'a> Runtime<'a> {
"editor"
}
- /// Get the argument name for generating the completion
- pub fn arg_generate_compl() -> &'static str {
- "generate-completion"
- }
-
/// Extract the Store object from the Runtime object, destroying the Runtime object
///
/// # Warning
@@ -353,11 +317,6 @@ impl<'a> Runtime<'a> {
"logging-destinations"
}
- /// Get the argument name for pipe magic
- pub fn pipe_magic_name() -> &'static str {
- "pipe-magic"
- }
-
/// Initialize the internal logger
fn init_logger(matches: &ArgMatches, config: Option<&Value>) {
use log::set_max_level;
@@ -472,7 +431,7 @@ impl<'a> Runtime<'a> {
.ok_or_else(|| RuntimeErrorKind::IOError.into())
.map_dbg(|s| format!("Editing with '{}'", s))
.and_then(|s| {
- let mut split = s.split(" ");
+ let mut split = s.split_whitespace();
let command = split.next();
if command.is_none() {
return Ok(None)
@@ -486,10 +445,10 @@ impl<'a> Runtime<'a> {
}
pub fn stdout(&self) -> OutputProxy {
- if self.use_pipe_magic && !self.stdout_is_tty {
- OutputProxy::Err(::std::io::stderr())
- } else {
+ if self.stdout_is_tty {
OutputProxy::Out(::std::io::stdout())
+ } else {
+ OutputProxy::Err(::std::io::stderr())
}
}
@@ -498,10 +457,10 @@ impl<'a> Runtime<'a> {
}
pub fn stdin(&self) -> Option<Stdin> {
- if self.use_pipe_magic && !self.stdin_is_tty {
- None
- } else {
+ if self.stdin_is_tty {
Some(::std::io::stdin())
+ } else {
+ None
}
}
@@ -520,10 +479,16 @@ impl<'a> Runtime<'a> {
/// 3. The `ArgMatches` object from the call, so that this routine can forward all flags passed
/// to the `bar` subcommand.
///
+ /// # Warning
+ ///
+ /// If, and only if, the subcommand does not exist (as in `::std::io::ErrorKind::NotFound`),
+ /// this function exits with 1 as exit status.
+ ///
/// # Return value
///
/// On success, the exit status object of the `Command` invocation is returned.
- /// On Error, a RuntimeError object is returned.
+ /// On Error, a RuntimeError object is returned. This is also the case if writing the error
+ /// message does not work.
///
/// # Details
///
@@ -573,7 +538,7 @@ impl<'a> Runtime<'a> {
return e;
}
- e
+ ::std::process::exit(1)
},
_ => e,
})