From ee02906ce9daac08f08c5bf3293d95c14b2ffdca Mon Sep 17 00:00:00 2001 From: Ian Letourneau Date: Tue, 1 Jul 2025 21:08:19 +0000 Subject: [PATCH] fix(composer): spawn commands to allow interaction (#71) Using `Command::output()` executes the command and wait for it to be finished before returning the output. Though in some cases the user might need to interact with the CLI before continuing, which hangs the command execution. Instead, using `Command::spawn()` allows to forward stdin/stdout to the parent process. Reviewed-on: https://git.nationtech.io/NationTech/harmony/pulls/71 Reviewed-by: johnride --- harmony_composer/src/main.rs | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/harmony_composer/src/main.rs b/harmony_composer/src/main.rs index 0bdb7be..648977e 100644 --- a/harmony_composer/src/main.rs +++ b/harmony_composer/src/main.rs @@ -73,10 +73,9 @@ async fn main() { .try_exists() .expect("couldn't check if path exists"); - let harmony_bin_path: PathBuf; - match harmony_path { + let harmony_bin_path: PathBuf = match harmony_path { true => { - harmony_bin_path = compile_harmony( + compile_harmony( cli_args.compile_method, cli_args.compile_platform, cli_args.harmony_path.clone(), @@ -84,7 +83,7 @@ async fn main() { .await } false => todo!("implement autodetect code"), - } + }; match cli_args.command { Some(command) => match command { @@ -103,8 +102,10 @@ async fn main() { }; let check_output = Command::new(check_script) - .output() - .expect("failed to run check script"); + .spawn() + .expect("failed to run check script") + .wait_with_output() + .unwrap(); info!( "check stdout: {}, check stderr: {}", String::from_utf8(check_output.stdout).expect("couldn't parse from utf8"), @@ -112,18 +113,16 @@ async fn main() { ); } Commands::Deploy(args) => { - if args.staging { - todo!("implement staging deployment"); + let deploy = if args.staging { + todo!("implement staging deployment") + } else if args.prod { + todo!("implement prod deployment") + } else { + Command::new(harmony_bin_path).arg("-y").arg("-a").spawn() } + .expect("failed to run harmony deploy"); - if args.prod { - todo!("implement prod deployment"); - } - let deploy_output = Command::new(harmony_bin_path) - .arg("-y") - .arg("-a") - .output() - .expect("failed to run harmony deploy"); + let deploy_output = deploy.wait_with_output().unwrap(); println!( "deploy output: {}", String::from_utf8(deploy_output.stdout).expect("couldn't parse from utf8")