summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2020-12-08 11:52:09 +0100
committerMatthias Beyer <mail@beyermatthias.de>2020-12-08 12:00:07 +0100
commit09d19c7c8c5102f9be477aa848769fc12d4c7fa1 (patch)
treef522fce9aed01e749a0e838cb473c89bfc81f8f8
parent386939049a493499c979364e871fef78fd236028 (diff)
Add helper flag in package_print_format to check whether any other flag was requested
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--src/config/util.rs2
-rw-r--r--src/ui.rs19
2 files changed, 21 insertions, 0 deletions
diff --git a/src/config/util.rs b/src/config/util.rs
index c1f302d..052899f 100644
--- a/src/config/util.rs
+++ b/src/config/util.rs
@@ -5,6 +5,7 @@ pub fn default_progress_format() -> String {
pub fn default_package_print_format() -> String {
String::from(indoc::indoc!(r#"
{{i}} - {{p.name}} : {{p.version}}
+ {{~ #if print_any }}
==================================
{{~#if print_sources}}
@@ -54,6 +55,7 @@ pub fn default_package_print_format() -> String {
{{~#if print_script}}
{{script}}
{{/if~}}
+ {{~ /if ~}}
"#))
}
diff --git a/src/ui.rs b/src/ui.rs
index becacb5..1c82943 100644
--- a/src/ui.rs
+++ b/src/ui.rs
@@ -44,6 +44,24 @@ pub struct PackagePrintFlags {
pub script_highlighting: bool,
}
+impl PackagePrintFlags {
+ // Helper to check whether any of the CLI args requested one of these flags.
+ //
+ // The print_build_deps and print_runtime_deps as well as the script_highlighting and
+ // script_line_numbers is not included, because these only modify what to print and not whether
+ // to print.
+ fn print_any(&self) -> bool {
+ self.print_sources
+ || self.print_dependencies
+ || self.print_patches
+ || self.print_env
+ || self.print_flags
+ || self.print_deny_images
+ || self.print_phases
+ || self.print_script
+ }
+}
+
pub fn print_packages<'a, I>(out: &mut dyn Write,
format: &str,
iter: I,
@@ -82,6 +100,7 @@ fn print_package(out: &mut dyn Write,
data.insert("i" , serde_json::Value::Number(serde_json::Number::from(i)));
data.insert("p" , serde_json::to_value(package)?);
data.insert("script" , serde_json::Value::String(script));
+ data.insert("print_any" , serde_json::Value::Bool(flags.print_any()));
data.insert("print_runtime_deps" , serde_json::Value::Bool(flags.print_runtime_deps));
data.insert("print_build_deps" , serde_json::Value::Bool(flags.print_build_deps));
data.insert("print_sources" , serde_json::Value::Bool(flags.print_sources));