Add a prerequisites check
This commit is contained in:
parent
6fa97f2e4a
commit
4bb04c7a98
44
Cargo.lock
generated
44
Cargo.lock
generated
@ -61,7 +61,7 @@ version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648"
|
||||
dependencies = [
|
||||
"windows-sys",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -71,7 +71,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"windows-sys",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -341,7 +341,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -405,6 +405,7 @@ dependencies = [
|
||||
"serde_yaml",
|
||||
"tempfile",
|
||||
"time",
|
||||
"which",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -413,6 +414,15 @@ version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7"
|
||||
|
||||
[[package]]
|
||||
name = "home"
|
||||
version = "0.5.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5"
|
||||
dependencies = [
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "humantime"
|
||||
version = "2.1.0"
|
||||
@ -460,7 +470,7 @@ checksum = "0bad00257d07be169d870ab665980b06cdb366d792ad690bf2e76876dc503455"
|
||||
dependencies = [
|
||||
"hermit-abi",
|
||||
"rustix",
|
||||
"windows-sys",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -664,7 +674,7 @@ dependencies = [
|
||||
"errno",
|
||||
"libc",
|
||||
"linux-raw-sys",
|
||||
"windows-sys",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -779,7 +789,7 @@ dependencies = [
|
||||
"fastrand",
|
||||
"redox_syscall",
|
||||
"rustix",
|
||||
"windows-sys",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -940,6 +950,19 @@ version = "0.2.89"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f"
|
||||
|
||||
[[package]]
|
||||
name = "which"
|
||||
version = "5.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9bf3ea8596f3a0dd5980b46430f2058dfe2c36a27ccfbb1845d6fbfcd9ba6e14"
|
||||
dependencies = [
|
||||
"either",
|
||||
"home",
|
||||
"once_cell",
|
||||
"rustix",
|
||||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.9"
|
||||
@ -980,6 +1003,15 @@ dependencies = [
|
||||
"windows-targets 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
|
||||
dependencies = [
|
||||
"windows-targets 0.48.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.52.0"
|
||||
|
@ -21,3 +21,4 @@ serde_json = "1.0.110"
|
||||
serde_yaml = "0.9.29"
|
||||
tempfile = "3.9.0"
|
||||
time = { version = "0.3.31", features = ["serde", "formatting", "parsing"]}
|
||||
which = "5.0.0"
|
||||
|
@ -189,11 +189,9 @@ impl Chart {
|
||||
return Err(Box::from("unknown repository kind is found"));
|
||||
}
|
||||
}
|
||||
None => {
|
||||
Err(Box::from(
|
||||
None => Err(Box::from(
|
||||
"repository object is not filled up for the chart",
|
||||
))
|
||||
}
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
25
src/main.rs
25
src/main.rs
@ -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()) {
|
||||
|
@ -36,8 +36,7 @@ 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 {
|
||||
Ok(res) => match res {
|
||||
crate::config::RepositoryKind::Helm => {
|
||||
let helm: helm::Helm = chart.into();
|
||||
Ok(Box::new(helm))
|
||||
@ -46,8 +45,7 @@ pub(crate) fn repo_from_chart(chart: Chart) -> Result<Box<dyn Repo>, Box<dyn std
|
||||
let git: git::Git = chart.into();
|
||||
Ok(Box::new(git))
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user