summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2020-12-08 11:41:36 +0100
committerMatthias Beyer <mail@beyermatthias.de>2020-12-08 12:00:07 +0100
commit386939049a493499c979364e871fef78fd236028 (patch)
tree8b49c1b1a94eacd087320db29f3c6a7603140547 /src
parentf6968d182d4fd84b06e07f741af11088de91e976 (diff)
Cleanup: Use struct for flags, to be more typesafe
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'src')
-rw-r--r--src/commands/dependencies_of.rs33
-rw-r--r--src/commands/find_pkg.rs33
-rw-r--r--src/commands/what_depends.rs33
-rw-r--r--src/ui.rs84
4 files changed, 78 insertions, 105 deletions
diff --git a/src/commands/dependencies_of.rs b/src/commands/dependencies_of.rs
index 2a14e26..701e7f7 100644
--- a/src/commands/dependencies_of.rs
+++ b/src/commands/dependencies_of.rs
@@ -30,22 +30,21 @@ pub async fn dependencies_of(matches: &ArgMatches, config: &Configuration, repo:
print_runtime_deps,
print_build_deps);
- crate::ui::print_packages(&mut stdout,
- format,
- iter,
- config,
- print_runtime_deps,
- print_build_deps,
- false, // "print_sources"
- true, // "print_dependencies"
- false, // "print_patches"
- false, // "print_env"
- false, // "print_flags"
- false, // "print_deny_images"
- false, // "print_phases"
- false, // "print_script"
- false, // script_line_numbers
- false, // script_highlighting
- )
+ let flags = crate::ui::PackagePrintFlags {
+ print_runtime_deps,
+ print_build_deps,
+ print_sources: false,
+ print_dependencies: true,
+ print_patches: false,
+ print_env: false,
+ print_flags: false,
+ print_deny_images: false,
+ print_phases: false,
+ print_script: false,
+ script_line_numbers: false,
+ script_highlighting: false,
+ };
+
+ crate::ui::print_packages(&mut stdout, format, iter, config, &flags)
}
diff --git a/src/commands/find_pkg.rs b/src/commands/find_pkg.rs
index fd861c6..a6e302a 100644
--- a/src/commands/find_pkg.rs
+++ b/src/commands/find_pkg.rs
@@ -39,24 +39,23 @@ pub async fn find_pkg(matches: &ArgMatches, config: &Configuration, repo: Reposi
}
Ok(())
} else {
+ let flags = crate::ui::PackagePrintFlags {
+ print_runtime_deps : crate::commands::util::getbool(matches, "dependency_type", crate::cli::IDENT_DEPENDENCY_TYPE_RUNTIME),
+ print_build_deps : crate::commands::util::getbool(matches, "dependency_type", crate::cli::IDENT_DEPENDENCY_TYPE_BUILD),
+ print_sources : matches.is_present("show_sources"),
+ print_dependencies : matches.is_present("show_dependencies"),
+ print_patches : matches.is_present("show_patches"),
+ print_env : matches.is_present("show_env"),
+ print_flags : matches.is_present("show_flags"),
+ print_deny_images : matches.is_present("show_deny_images"),
+ print_phases : matches.is_present("show_phases"),
+ print_script : matches.is_present("show_script"),
+ script_line_numbers : !matches.is_present("no_script_line_numbers"),
+ script_highlighting : !matches.is_present("no_script_highlight"),
+ };
+
let format = config.package_print_format();
- crate::ui::print_packages(&mut outlock,
- format,
- iter,
- config,
- crate::commands::util::getbool(matches, "dependency_type", crate::cli::IDENT_DEPENDENCY_TYPE_RUNTIME),
- crate::commands::util::getbool(matches, "dependency_type", crate::cli::IDENT_DEPENDENCY_TYPE_BUILD),
- matches.is_present("show_sources"),
- matches.is_present("show_dependencies"),
- matches.is_present("show_patches"),
- matches.is_present("show_env"),
- matches.is_present("show_flags"),
- matches.is_present("show_deny_images"),
- matches.is_present("show_phases"),
- matches.is_present("show_script"),
- !matches.is_present("no_script_line_numbers"),
- !matches.is_present("no_script_highlight")
- )
+ crate::ui::print_packages(&mut outlock, format, iter, config, &flags)
}
}
diff --git a/src/commands/what_depends.rs b/src/commands/what_depends.rs
index 9520027..1d3ed07 100644
--- a/src/commands/what_depends.rs
+++ b/src/commands/what_depends.rs
@@ -35,22 +35,21 @@ pub async fn what_depends(matches: &ArgMatches, config: &Configuration, repo: Re
.inspect(|pkg| trace!("Found package: {:?}", pkg))
.collect::<Result<Vec<_>>>()?;
- crate::ui::print_packages(&mut stdout,
- format,
- packages.into_iter(),
- config,
- print_runtime_deps,
- print_build_deps,
- false, // "print_sources"
- true, // "print_dependencies"
- false, // "print_patches"
- false, // "print_env"
- false, // "print_flags"
- false, // "print_deny_images"
- false, // "print_phases"
- false, // "print_script"
- false, // script_line_numbers
- false, // script_highlighting
- )
+ let flags = crate::ui::PackagePrintFlags {
+ print_runtime_deps,
+ print_build_deps,
+ print_sources: false,
+ print_dependencies: true,
+ print_patches: false,
+ print_env: false,
+ print_flags: false,
+ print_deny_images: false,
+ print_phases: false,
+ print_script: false,
+ script_line_numbers: false,
+ script_highlighting: false,
+ };
+
+ crate::ui::print_packages(&mut stdout, format, packages.into_iter(), config, &flags)
}
diff --git a/src/ui.rs b/src/ui.rs
index 7c4bc71..becacb5 100644
--- a/src/ui.rs
+++ b/src/ui.rs
@@ -29,22 +29,26 @@ pub fn package_repo_cleanness_check(repo_path: &Path) -> Result<()> {
}
}
+pub struct PackagePrintFlags {
+ pub print_runtime_deps: bool,
+ pub print_build_deps: bool,
+ pub print_sources: bool,
+ pub print_dependencies: bool,
+ pub print_patches: bool,
+ pub print_env: bool,
+ pub print_flags: bool,
+ pub print_deny_images: bool,
+ pub print_phases: bool,
+ pub print_script: bool,
+ pub script_line_numbers: bool,
+ pub script_highlighting: bool,
+}
+
pub fn print_packages<'a, I>(out: &mut dyn Write,
format: &str,
iter: I,
config: &Configuration,
- print_runtime_deps: bool,
- print_build_deps: bool,
- print_sources: bool,
- print_dependencies: bool,
- print_patches: bool,
- print_env: bool,
- print_flags: bool,
- print_deny_images: bool,
- print_phases: bool,
- print_script: bool,
- script_line_numbers: bool,
- script_highlighting: bool)
+ flags: &PackagePrintFlags)
-> Result<()>
where I: Iterator<Item = &'a Package>
{
@@ -52,24 +56,7 @@ pub fn print_packages<'a, I>(out: &mut dyn Write,
hb.register_template_string("package", format)?;
for (i, package) in iter.enumerate() {
- print_package(out,
- &hb,
- i,
- package,
- config,
- print_runtime_deps,
- print_build_deps,
- print_sources,
- print_dependencies,
- print_patches,
- print_env,
- print_flags,
- print_deny_images,
- print_phases,
- print_script,
- script_line_numbers,
- script_highlighting
- )?;
+ print_package(out, &hb, i, package, config, flags)?;
}
Ok(())
@@ -80,42 +67,31 @@ fn print_package(out: &mut dyn Write,
i: usize,
package: &Package,
config: &Configuration,
- print_runtime_deps: bool,
- print_build_deps: bool,
- print_sources: bool,
- print_dependencies: bool,
- print_patches: bool,
- print_env: bool,
- print_flags: bool,
- print_deny_images: bool,
- print_phases: bool,
- print_script: bool,
- script_line_numbers: bool,
- script_highlighting: bool)
+ flags: &PackagePrintFlags)
-> Result<()>
{
let script = ScriptBuilder::new(&Shebang::from(config.shebang().clone()))
.build(package, config.available_phases(), *config.strict_script_interpolation())?;
let script = crate::ui::script_to_printable(script.as_ref(),
- script_highlighting,
+ flags.script_highlighting,
config.script_highlight_theme().as_ref(),
- script_line_numbers)?;
+ flags.script_line_numbers)?;
let mut data = BTreeMap::new();
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_runtime_deps" , serde_json::Value::Bool(print_runtime_deps));
- data.insert("print_build_deps" , serde_json::Value::Bool(print_build_deps));
- data.insert("print_sources" , serde_json::Value::Bool(print_sources));
- data.insert("print_dependencies" , serde_json::Value::Bool(print_dependencies));
- data.insert("print_patches" , serde_json::Value::Bool(print_patches));
- data.insert("print_env" , serde_json::Value::Bool(print_env));
- data.insert("print_flags" , serde_json::Value::Bool(print_flags));
- data.insert("print_deny_images" , serde_json::Value::Bool(print_deny_images));
- data.insert("print_phases" , serde_json::Value::Bool(print_phases));
- data.insert("print_script" , serde_json::Value::Bool(print_script));
+ 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));
+ data.insert("print_dependencies" , serde_json::Value::Bool(flags.print_dependencies));
+ data.insert("print_patches" , serde_json::Value::Bool(flags.print_patches));
+ data.insert("print_env" , serde_json::Value::Bool(flags.print_env));
+ data.insert("print_flags" , serde_json::Value::Bool(flags.print_flags));
+ data.insert("print_deny_images" , serde_json::Value::Bool(flags.print_deny_images));
+ data.insert("print_phases" , serde_json::Value::Bool(flags.print_phases));
+ data.insert("print_script" , serde_json::Value::Bool(flags.print_script));
hb.render("package", &data)