Add a prerequisites check

This commit is contained in:
2024-01-10 22:48:56 +01:00
parent 6fa97f2e4a
commit 4bb04c7a98
5 changed files with 75 additions and 23 deletions

View File

@ -189,11 +189,9 @@ impl Chart {
return Err(Box::from("unknown repository kind is found"));
}
}
None => {
Err(Box::from(
"repository object is not filled up for the chart",
))
}
None => Err(Box::from(
"repository object is not filled up for the chart",
)),
}
}
}

View File

@ -8,7 +8,7 @@ pub(crate) mod template;
use clap::Parser;
use log::{error, info};
use std::collections::HashMap;
use std::fs;
use std::{env, fs};
use std::{fs::create_dir, path::PathBuf, process::exit};
use tempfile::TempDir;
@ -27,6 +27,8 @@ struct Args {
/// Dry run
#[arg(short, long, default_value = "false")]
dry_run: bool,
#[arg(long, default_value = "false")]
skip_prerequisites_check: bool,
/// Init git patch. Use it if you want to create git patch for a chart
/// It's going to pull a chart and init a git repo there, so you can
/// apply changes and create a patch file
@ -36,9 +38,30 @@ struct Args {
init_git_patch: Option<Vec<String>>,
}
fn check_prerequisites() -> Result<(), Box<dyn std::error::Error>> {
info!("checking prerequisites");
let prerequisites = vec!["helm", "yq", "helm"];
for bin in prerequisites {
info!("checking {}", bin);
which::which(bin)?;
}
Ok(())
}
fn main() {
// Prepare the logger
if env::var("RUST_LOG").is_err() {
env::set_var("RUST_LOG", "info")
}
env_logger::init();
let args = Args::parse();
if !args.skip_prerequisites_check {
if let Err(err) = check_prerequisites() {
error!("{}", err);
exit(1);
}
}
// Prepare the workdir
let workdir_path = match args.workdir {
Some(res) => match create_dir(res.clone()) {

View File

@ -36,18 +36,16 @@ pub(crate) struct Version {
pub(crate) fn repo_from_chart(chart: Chart) -> Result<Box<dyn Repo>, Box<dyn std::error::Error>> {
match chart.get_repo_kind() {
Ok(res) => {
match res {
crate::config::RepositoryKind::Helm => {
let helm: helm::Helm = chart.into();
Ok(Box::new(helm))
}
crate::config::RepositoryKind::Git => {
let git: git::Git = chart.into();
Ok(Box::new(git))
}
Ok(res) => match res {
crate::config::RepositoryKind::Helm => {
let helm: helm::Helm = chart.into();
Ok(Box::new(helm))
}
}
crate::config::RepositoryKind::Git => {
let git: git::Git = chart.into();
Ok(Box::new(git))
}
},
Err(err) => Err(err),
}
}