add script option to deploy command

This commit is contained in:
Sayantan Karmakar 2022-04-10 18:40:13 +05:30
parent 1a3b5757ab
commit 9f83e6cbdd
2 changed files with 28 additions and 3 deletions

View File

@ -12,7 +12,11 @@ use crate::{
utils::is_initialized,
};
pub fn deploy(cfg_override: &ConfigOverride, cluster: Option<Cluster>) -> Result<()> {
pub fn deploy(
cfg_override: &ConfigOverride,
cluster: Option<Cluster>,
script: Option<String>,
) -> Result<()> {
with_config(cfg_override, |cfg| {
if !is_initialized() {
return Err(DevToolError::NotInitialized.into());
@ -48,6 +52,20 @@ pub fn deploy(cfg_override: &ConfigOverride, cluster: Option<Cluster>) -> Result
println!("Deploy Successful");
if script.is_some() {
let script_exit = std::process::Command::new("bash")
.arg("-c")
.arg(script.unwrap())
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.output()
.unwrap();
if !script_exit.status.success() {
std::process::exit(exit.status.code().unwrap_or(1));
}
}
Ok(())
})
}

View File

@ -22,13 +22,20 @@ pub struct Opts {
pub enum Command {
Init,
Instance,
Deploy { cluster: Option<Cluster> },
Deploy {
cluster: Option<Cluster>,
#[clap(long)]
script: Option<String>,
},
}
pub fn entry(opts: Opts) -> Result<()> {
match opts.command {
Command::Init => commands::init(),
Command::Instance => commands::instance(),
Command::Deploy { cluster } => commands::deploy(&opts.cfg_override, cluster),
Command::Deploy { cluster, script } => {
commands::deploy(&opts.cfg_override, cluster, script)
}
}
}