summaryrefslogtreecommitdiffstats
path: root/lib/core/libimagrt/src/runtime.rs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/core/libimagrt/src/runtime.rs')
-rw-r--r--lib/core/libimagrt/src/runtime.rs35
1 files changed, 30 insertions, 5 deletions
diff --git a/lib/core/libimagrt/src/runtime.rs b/lib/core/libimagrt/src/runtime.rs
index 90ad0920..aaa89772 100644
--- a/lib/core/libimagrt/src/runtime.rs
+++ b/lib/core/libimagrt/src/runtime.rs
@@ -61,6 +61,7 @@ pub struct Runtime<'a> {
input_data: bool,
output_data: bool,
+ blackhole_stdout: bool,
}
impl<'a> Runtime<'a> {
@@ -138,15 +139,17 @@ impl<'a> Runtime<'a> {
Store::new(storepath, &config)
};
- let has_output_pipe = !atty::is(atty::Stream::Stdout);
- let has_input_pipe = !atty::is(atty::Stream::Stdin);
- let input_data = matches.is_present("input-pipe-data");
- let output_data = matches.is_present("output-pipe-data");
+ let has_output_pipe = !atty::is(atty::Stream::Stdout);
+ let has_input_pipe = !atty::is(atty::Stream::Stdin);
+ let input_data = matches.is_present("input-pipe-data");
+ let output_data = matches.is_present("output-pipe-data");
+ let blackhole_stdout = matches.is_present("blackhole-stdout");
debug!("has output pipe = {}", has_output_pipe);
debug!("has input pipe = {}", has_input_pipe);
debug!("input pipe data = {}", input_data);
debug!("output pipe data = {}", output_data);
+ debug!("blackhole output = {}", blackhole_stdout);
store_result.map(|store| Runtime {
cli_matches: matches,
@@ -158,6 +161,7 @@ impl<'a> Runtime<'a> {
has_input_pipe,
input_data,
output_data,
+ blackhole_stdout,
})
.context(anyhow!("Cannot instantiate runtime"))
.map_err(Error::from)
@@ -257,7 +261,22 @@ impl<'a> Runtime<'a> {
.takes_value(false)
.multiple(false)
.help("Do not print imag ids to stdout if stdout is a pipe.")
- )
+ )
+
+ .arg(Arg::with_name("blackhole-stdout")
+ .long("blackhole")
+ .short("B")
+ .required(false)
+ .takes_value(false)
+ .multiple(false)
+ .help("Do not print normal output")
+ .long_help(indoc!(r#"
+ This flag can be used to ignore output.
+ For example, if imag is used in a piping context, which pipes the Store IDs, the
+ normal output is automatically redirected to stderr. To ignore the normal output
+ instead, this flag can be passed.
+ "#))
+ )
}
@@ -420,6 +439,10 @@ impl<'a> Runtime<'a> {
self.has_input_pipe
}
+ pub fn output_is_blackholed(&self) -> bool {
+ self.blackhole_stdout
+ }
+
/// Check whether the runtime expects imag ids from stdin
pub fn ids_from_stdin(&self) -> bool {
self.input_is_pipe() && !self.input_data
@@ -438,6 +461,8 @@ impl<'a> Runtime<'a> {
pub fn stdout(&self) -> OutputProxy {
if self.output_is_pipe() && self.output_data {
OutputProxy::Out(::std::io::stdout())
+ } else if self.output_is_blackholed() {
+ OutputProxy::Sink
} else {
OutputProxy::Err(::std::io::stderr())
}