Try building and add env flag

This commit is contained in:
Nikolai Rodionov
2023-02-07 12:15:34 +01:00
parent 1af6275c43
commit b1a453ef21
3 changed files with 54 additions and 14 deletions

View File

@ -8,13 +8,15 @@ use std::{borrow::Borrow, io::Result, process::Command};
pub(crate) struct Helmfile {
path: String,
env: String,
}
impl Connector for Helmfile {
fn get_app(&self) -> Result<Vec<types::HelmChart>> {
let cmd: String = format!(
"helmfile -f {} list --output json | jq '[.[] | {{chart: .name, version: .version}}]'",
self.path
"helmfile -f {} -e {} list --output json | jq '[.[] | {{chart: .name, version: .version}}]'",
self.path,
self.env
)
.to_string();
@ -35,7 +37,7 @@ impl Connector for Helmfile {
}
}
fn sync_repos(&self) -> Result<()> {
let cmd: String = format!("helmfile -f {} sync", self.path);
let cmd: String = format!("helmfile -f {} -e {} sync", self.path, self.env);
Command::new("bash")
.arg("-c")
.arg(cmd)
@ -47,7 +49,7 @@ impl Connector for Helmfile {
type ConnectorType = Helmfile;
}
impl Helmfile {
pub(crate) fn init(path: String) -> Self {
Self { path: path }
pub(crate) fn init(path: String, env: String) -> Self {
Self {path, env}
}
}

View File

@ -43,6 +43,9 @@ struct Args {
/// Path to the helmfile
#[clap(short, long, value_parser, default_value = "./")]
path: String,
/// Pass an environment to the helmfile
#[arg(long, required = false, default_value = "default")]
helmfile_environment: String,
/// Should execution be failed if you have outdated charts
#[clap(short, long, action, default_value_t = false, env = "OUTDATED_FAIL")]
outdated_fail: bool,
@ -85,7 +88,7 @@ fn main() {
let charts = match args.kind {
Kinds::Argo => Argo::init().get_app(),
Kinds::Helm => Helm::init().get_app(),
Kinds::Helmfile => Helmfile::init(args.path.clone()).get_app(),
Kinds::Helmfile => Helmfile::init(args.path.clone(), args.helmfile_environment.clone()).get_app(),
}
.unwrap();
@ -94,7 +97,7 @@ fn main() {
let res = match args.kind {
Kinds::Argo => Argo::init().sync_repos(),
Kinds::Helm => Helm::init().sync_repos(),
Kinds::Helmfile => Helmfile::init(args.path).sync_repos(),
Kinds::Helmfile => Helmfile::init(args.path, args.helmfile_environment).sync_repos(),
};
match res {
Ok(_) => info!("helm repos are synced"),