summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@atos.net>2021-01-05 20:38:30 +0100
committerMatthias Beyer <matthias.beyer@atos.net>2021-01-12 15:05:15 +0100
commita7f90ff4feea95eccf9ff58120175164dde258fd (patch)
tree662c1834d72397d588841856bd397937ae048d96
parentc5521bb98a869ba56d8b77619f18d4dc8bc5c592 (diff)
Check whether all phases are available and used
Signed-off-by: Christoph Prokop <christoph.prokop@atos.net> Signed-off-by: Matthias Beyer <matthias.beyer@atos.net>
-rw-r--r--src/commands/util.rs19
1 files changed, 18 insertions, 1 deletions
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<PhaseName>) -> Result<()> {
+ let package_phasenames = pkg.phases().keys().collect::<Vec<_>>();
+
+ 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(())
+}
+