From a7f90ff4feea95eccf9ff58120175164dde258fd Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 5 Jan 2021 20:38:30 +0100 Subject: Check whether all phases are available and used Signed-off-by: Christoph Prokop Signed-off-by: Matthias Beyer --- src/commands/util.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/commands/util.rs b/src/commands/util.rs index 28ff5ea..674258d 100644 --- a/src/commands/util.rs +++ b/src/commands/util.rs @@ -7,9 +7,10 @@ use log::{error, info, trace}; use tokio::stream::StreamExt; use crate::config::*; -use crate::package::Shebang; use crate::package::Package; +use crate::package::PhaseName; use crate::package::ScriptBuilder; +use crate::package::Shebang; pub fn getbool(m: &ArgMatches, name: &str, cmp: &str) -> bool { // unwrap is safe here because clap is configured with default values @@ -26,6 +27,8 @@ pub async fn lint_packages<'a, I>(iter: I, linter: &Path, config: &Configuration let bar = bar.clone(); async move { trace!("Linting script of {} {} with '{}'", pkg.name(), pkg.version(), linter.display()); + let _ = all_phases_available(pkg, config.available_phases())?; + let cmd = tokio::process::Command::new(linter); let script = ScriptBuilder::new(&shebang) .build(pkg, config.available_phases(), *config.strict_script_interpolation())?; @@ -79,3 +82,17 @@ pub async fn lint_packages<'a, I>(iter: I, linter: &Path, config: &Configuration } } +fn all_phases_available(pkg: &Package, available_phases: &Vec) -> Result<()> { + let package_phasenames = pkg.phases().keys().collect::>(); + + if let Some(phase) = package_phasenames.iter().filter(|name| !available_phases.contains(name)).next() { + return Err(anyhow!("Phase '{}' available in {} {}, but not in config", phase.as_str(), pkg.name(), pkg.version())) + } + + if let Some(phase) = available_phases.iter().filter(|name| !package_phasenames.contains(name)).next() { + return Err(anyhow!("Phase '{}' not configured in {} {}", phase.as_str(), pkg.name(), pkg.version())) + } + + Ok(()) +} + -- cgit v1.2.3