Merge branch 'runtime-io-features' into master-ff
This commit is contained in:
commit
0f32471a03
3 changed files with 28 additions and 30 deletions
|
@ -419,7 +419,7 @@ fn forward_commandline_arguments(m: &ArgMatches, scmd: &mut Vec<String>) {
|
||||||
push(Some("editor"),
|
push(Some("editor"),
|
||||||
Runtime::arg_editor_name(), m , scmd);
|
Runtime::arg_editor_name(), m , scmd);
|
||||||
|
|
||||||
push(None , Runtime::arg_logdest_name() , m , scmd);
|
push(Some("ignore-ids"),
|
||||||
|
Runtime::arg_ignore_ids_name(), m , scmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -280,8 +280,8 @@ fn translate_destinations(raw: &Vec<Value>) -> Result<Vec<LogDestination>> {
|
||||||
fn aggregate_global_destinations(matches: &ArgMatches, config: Option<&Value>)
|
fn aggregate_global_destinations(matches: &ArgMatches, config: Option<&Value>)
|
||||||
-> Result<Vec<LogDestination>>
|
-> Result<Vec<LogDestination>>
|
||||||
{
|
{
|
||||||
|
|
||||||
match config {
|
match config {
|
||||||
|
None => Ok(vec![LogDestination::default()]),
|
||||||
Some(cfg) => cfg
|
Some(cfg) => cfg
|
||||||
.read("imag.logging.destinations")
|
.read("imag.logging.destinations")
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
|
@ -293,21 +293,6 @@ fn aggregate_global_destinations(matches: &ArgMatches, config: Option<&Value>)
|
||||||
Error::from(err_msg(msg))
|
Error::from(err_msg(msg))
|
||||||
})
|
})
|
||||||
.and_then(translate_destinations),
|
.and_then(translate_destinations),
|
||||||
None => {
|
|
||||||
if let Some(values) = matches.value_of(Runtime::arg_logdest_name()) {
|
|
||||||
// parse logdest specification from commandline
|
|
||||||
|
|
||||||
values.split(",")
|
|
||||||
.fold(Ok(vec![]), move |acc, dest| {
|
|
||||||
acc.and_then(|mut v| {
|
|
||||||
v.push(translate_destination(dest)?);
|
|
||||||
Ok(v)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
Ok(vec![ LogDestination::default() ])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,6 +62,8 @@ pub struct Runtime<'a> {
|
||||||
|
|
||||||
has_output_pipe: bool,
|
has_output_pipe: bool,
|
||||||
has_input_pipe: bool,
|
has_input_pipe: bool,
|
||||||
|
|
||||||
|
ignore_ids: bool
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Runtime<'a> {
|
impl<'a> Runtime<'a> {
|
||||||
|
@ -146,9 +148,11 @@ impl<'a> Runtime<'a> {
|
||||||
|
|
||||||
let has_output_pipe = !atty::is(atty::Stream::Stdout);
|
let has_output_pipe = !atty::is(atty::Stream::Stdout);
|
||||||
let has_input_pipe = !atty::is(atty::Stream::Stdin);
|
let has_input_pipe = !atty::is(atty::Stream::Stdin);
|
||||||
|
let ignore_ids = matches.is_present(Runtime::arg_ignore_ids_name());
|
||||||
|
|
||||||
debug!("has output pipe = {}", has_output_pipe);
|
debug!("has output pipe = {}", has_output_pipe);
|
||||||
debug!("has input pipe = {}", has_input_pipe);
|
debug!("has input pipe = {}", has_input_pipe);
|
||||||
|
debug!("ignore ids = {}", ignore_ids);
|
||||||
|
|
||||||
store_result.map(|store| Runtime {
|
store_result.map(|store| Runtime {
|
||||||
cli_matches: matches,
|
cli_matches: matches,
|
||||||
|
@ -158,6 +162,7 @@ impl<'a> Runtime<'a> {
|
||||||
|
|
||||||
has_output_pipe,
|
has_output_pipe,
|
||||||
has_input_pipe,
|
has_input_pipe,
|
||||||
|
ignore_ids,
|
||||||
})
|
})
|
||||||
.context(err_msg("Cannot instantiate runtime"))
|
.context(err_msg("Cannot instantiate runtime"))
|
||||||
.map_err(Error::from)
|
.map_err(Error::from)
|
||||||
|
@ -240,12 +245,12 @@ impl<'a> Runtime<'a> {
|
||||||
.required(false)
|
.required(false)
|
||||||
.takes_value(true))
|
.takes_value(true))
|
||||||
|
|
||||||
.arg(Arg::with_name(Runtime::arg_logdest_name())
|
.arg(Arg::with_name(Runtime::arg_ignore_ids_name())
|
||||||
.long(Runtime::arg_logdest_name())
|
.long(Runtime::arg_ignore_ids_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")
|
.help("Do not assume that the output is a pipe to another imag command. This overrides the default behaviour where imag only prints the IDs of the touched entries to stdout if stdout is a pipe.")
|
||||||
|
.long_help("Without this flag, imag assumes that if stdout is a pipe, the command imag pipes to is also an imag command. Thus, it prints the IDs of the processed entries to stdout and automatically redirects the command output to stderr. By providing this flag, this behaviour gets overridden: The IDs are not printed at all and the normal output is printed to stdout.")
|
||||||
.required(false)
|
.required(false)
|
||||||
.takes_value(true)
|
.takes_value(false))
|
||||||
.value_name("LOGDESTS"))
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -260,9 +265,15 @@ impl<'a> Runtime<'a> {
|
||||||
Runtime::arg_runtimepath_name(),
|
Runtime::arg_runtimepath_name(),
|
||||||
Runtime::arg_storepath_name(),
|
Runtime::arg_storepath_name(),
|
||||||
Runtime::arg_editor_name(),
|
Runtime::arg_editor_name(),
|
||||||
|
Runtime::arg_ignore_ids_name(),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the normal-output argument name for the Runtime
|
||||||
|
pub fn arg_ignore_ids_name() -> &'static str {
|
||||||
|
"ignore-ids"
|
||||||
|
}
|
||||||
|
|
||||||
/// Get the verbosity argument name for the Runtime
|
/// Get the verbosity argument name for the Runtime
|
||||||
pub fn arg_verbosity_name() -> &'static str {
|
pub fn arg_verbosity_name() -> &'static str {
|
||||||
"verbosity"
|
"verbosity"
|
||||||
|
@ -326,11 +337,6 @@ impl<'a> Runtime<'a> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the argument name for the logging destination
|
|
||||||
pub fn arg_logdest_name() -> &'static str {
|
|
||||||
"logging-destinations"
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "pub_logging_initialization")]
|
#[cfg(feature = "pub_logging_initialization")]
|
||||||
pub fn init_logger(matches: &ArgMatches, config: Option<&Value>) {
|
pub fn init_logger(matches: &ArgMatches, config: Option<&Value>) {
|
||||||
Self::_init_logger(matches, config)
|
Self::_init_logger(matches, config)
|
||||||
|
@ -461,8 +467,15 @@ impl<'a> Runtime<'a> {
|
||||||
self.has_output_pipe
|
self.has_output_pipe
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Check whether the runtime ignores touched ids
|
||||||
|
///
|
||||||
|
/// "Ignoring" in this context means whether the runtime prints them or not.
|
||||||
|
pub fn ignore_ids(&self) -> bool {
|
||||||
|
self.ignore_ids
|
||||||
|
}
|
||||||
|
|
||||||
pub fn stdout(&self) -> OutputProxy {
|
pub fn stdout(&self) -> OutputProxy {
|
||||||
if self.output_is_pipe() {
|
if self.output_is_pipe() && !self.ignore_ids {
|
||||||
OutputProxy::Err(::std::io::stderr())
|
OutputProxy::Err(::std::io::stderr())
|
||||||
} else {
|
} else {
|
||||||
OutputProxy::Out(::std::io::stdout())
|
OutputProxy::Out(::std::io::stdout())
|
||||||
|
@ -585,7 +598,7 @@ impl<'a> Runtime<'a> {
|
||||||
fn report_touched_id(&self, id: &StoreId, output: &mut StdoutLock) -> Result<()> {
|
fn report_touched_id(&self, id: &StoreId, output: &mut StdoutLock) -> Result<()> {
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
if self.output_is_pipe() {
|
if self.output_is_pipe() && !self.ignore_ids {
|
||||||
trace!("Reporting: {} to {:?}", id, output);
|
trace!("Reporting: {} to {:?}", id, output);
|
||||||
writeln!(output, "{}", id)?;
|
writeln!(output, "{}", id)?;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue