diff --git a/Cargo.lock b/Cargo.lock index bbf8083..09a76be 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2840,6 +2840,7 @@ dependencies = [ "docker_utils", "env_logger", "inquire", + "log", "tokio", ] diff --git a/harmony_composer/Cargo.toml b/harmony_composer/Cargo.toml index c9f8d82..87f15cc 100644 --- a/harmony_composer/Cargo.toml +++ b/harmony_composer/Cargo.toml @@ -11,5 +11,6 @@ clap = { version = "4.5.35", features = ["derive"] } inquire.workspace = true tokio.workspace = true env_logger.workspace = true +log.workspace = true cargo = "0.88.0" docker_utils = "0.2.3" diff --git a/harmony_composer/src/main.rs b/harmony_composer/src/main.rs index c715d98..dbeee37 100644 --- a/harmony_composer/src/main.rs +++ b/harmony_composer/src/main.rs @@ -4,19 +4,19 @@ use std::process::Command; use clap::builder::ArgPredicate; use clap::{Args, Parser, Subcommand}; use inquire::Confirm; +use log::{debug, info, warn}; #[derive(Parser)] -#[command(version, about, long_about = None)] -#[command(propagate_version = true)] +#[command(version, about, long_about = None, flatten_help = true, propagate_version = true)] struct GlobalArgs { - #[arg(long, default_value = "./harmony")] + #[arg(long, default_value = "harmony")] harmony_path: String, #[command(subcommand)] - command: Commands, + command: Option, } -#[derive(Subcommand)] +#[derive(Subcommand, Clone, Debug)] enum Commands { Check(CheckArgs), Package(PackageArgs), @@ -24,21 +24,19 @@ enum Commands { All(AllArgs), } -#[derive(Args)] +#[derive(Args, Clone, Debug)] struct CheckArgs { #[arg(long, default_value = "check.sh")] check_script_path: String, } -#[derive(Args)] +#[derive(Args, Clone, Debug)] struct PackageArgs { - #[arg(long, default_value_t = false)] - package: bool, #[arg(long, default_value_t = false)] publish: bool, } -#[derive(Args)] +#[derive(Args, Clone, Debug)] struct DeployArgs { #[arg(long, default_value_t = false)] staging: bool, @@ -50,71 +48,71 @@ struct DeployArgs { smoke_test: bool, } -#[derive(Args)] +#[derive(Args, Clone, Debug)] struct AllArgs { - #[arg(long, default_value = "check.sh")] - check_script_path: String, + #[command(flatten)] + check: CheckArgs, - #[arg(long, default_value_t = false)] - package: bool, + #[command(flatten)] + package: PackageArgs, - #[arg(long, default_value_t = false)] - publish: bool, - - #[arg(long, default_value_t = false)] - staging: bool, - - #[arg(long, default_value_t = false)] - prod: bool, - - #[arg(long, default_value_t = false)] - smoke_test: bool, + #[command(flatten)] + deploy: DeployArgs, } fn main() { + env_logger::init(); let cli_args = GlobalArgs::parse(); - let harmony_path = Path::new(&args.harmony_path).try_exists(); + let harmony_path = Path::new(&cli_args.harmony_path) + .try_exists() + .expect("couldn't check if path exists"); match harmony_path { - Ok(_path) => compile_harmony(args.harmony_path.clone()), - Err(_) => todo!("implement autodetect code"), + true => compile_harmony(cli_args.harmony_path.clone()), + false => todo!("implement autodetect code"), } match cli_args.command { - Commands::Check(args) => { - let check_script = match Path::new(&format!("{}/{}", cli_args.harmony_path, "check.sh")) + Some(command) => match command { + Commands::Check(args) => { + let check_script = match Path::new(&format!( + "{}/{}", + cli_args.harmony_path, args.check_script_path + )) .try_exists() - { - Ok(path) => path, - Err(_) => todo!("implement logic when couldn't find check script"), - }; + { + Ok(path) => path, + Err(_) => todo!("implement logic when couldn't find check script"), + }; - let check_output = Command::new("sh") - .arg("-c") - .arg(check_script.to_string()) - .output() - .expect("failed to run check script"); - } - Commands::Package(args) => { - if args.publish { - todo!("implement publish logic"); + let check_output = Command::new("sh") + .arg("-c") + .arg(check_script.to_string()) + .output() + .expect("failed to run check script"); } - todo!("implement packaging logic"); - } - Commands::Deploy(args) => { - if args.staging { - todo!("implement staging deployment"); + Commands::Package(args) => { + if args.publish { + todo!("implement publish logic"); + } + todo!("implement packaging logic"); } + Commands::Deploy(args) => { + if args.staging { + todo!("implement staging deployment"); + } - if args.prod { - todo!("implement prod deployment"); + if args.prod { + todo!("implement prod deployment"); + } + todo!("implement deployment logic"); } - todo!("implement deployment logic"); - } - Commands::All(args) => todo!( - "take all previous match arms and turn them into separate functions, and call them all one after the other" - ), + Commands::All(args) => todo!( + "take all previous match arms and turn them into separate functions, and call them all one after the other" + ), + }, + None => todo!("run interactively, ask for info on CLI"), } } @@ -127,14 +125,14 @@ fn compile_harmony(harmony_location: String) { &cargo::core::Workspace::new( &Path::new(&format!("{}/Cargo.toml", harmony_location)) .canonicalize() - .unwrap(), + .expect("Couldn't find Cargo.toml in harmony dir"), &gctx, ) .unwrap(), &cargo::ops::CompileOptions::new(&gctx, cargo::core::compiler::CompileMode::Build) .unwrap(), ) - .expect("build success"); + .expect("build didn't go successfully"); return; }