turn it into subcommands
This commit is contained in:
15
harmony_composer/Cargo.toml
Normal file
15
harmony_composer/Cargo.toml
Normal file
@@ -0,0 +1,15 @@
|
||||
[package]
|
||||
name = "harmony_composer"
|
||||
edition = "2024"
|
||||
version.workspace = true
|
||||
readme.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
[dependencies]
|
||||
assert_cmd = "2.0.17"
|
||||
clap = { version = "4.5.35", features = ["derive"] }
|
||||
inquire.workspace = true
|
||||
tokio.workspace = true
|
||||
env_logger.workspace = true
|
||||
cargo = "0.88.0"
|
||||
docker_utils = "0.2.3"
|
||||
144
harmony_composer/src/main.rs
Normal file
144
harmony_composer/src/main.rs
Normal file
@@ -0,0 +1,144 @@
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
|
||||
use clap::builder::ArgPredicate;
|
||||
use clap::{Args, Parser, Subcommand};
|
||||
use inquire::Confirm;
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(version, about, long_about = None)]
|
||||
#[command(propagate_version = true)]
|
||||
struct GlobalArgs {
|
||||
#[arg(long, default_value = "./harmony")]
|
||||
harmony_path: String,
|
||||
|
||||
#[command(subcommand)]
|
||||
command: Commands,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum Commands {
|
||||
Check(CheckArgs),
|
||||
Package(PackageArgs),
|
||||
Deploy(DeployArgs),
|
||||
All(AllArgs),
|
||||
}
|
||||
|
||||
#[derive(Args)]
|
||||
struct CheckArgs {
|
||||
#[arg(long, default_value = "check.sh")]
|
||||
check_script_path: String,
|
||||
}
|
||||
|
||||
#[derive(Args)]
|
||||
struct PackageArgs {
|
||||
#[arg(long, default_value_t = false)]
|
||||
package: bool,
|
||||
#[arg(long, default_value_t = false)]
|
||||
publish: bool,
|
||||
}
|
||||
|
||||
#[derive(Args)]
|
||||
struct DeployArgs {
|
||||
#[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,
|
||||
}
|
||||
|
||||
#[derive(Args)]
|
||||
struct AllArgs {
|
||||
#[arg(long, default_value = "check.sh")]
|
||||
check_script_path: String,
|
||||
|
||||
#[arg(long, default_value_t = false)]
|
||||
package: bool,
|
||||
|
||||
#[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,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let cli_args = GlobalArgs::parse();
|
||||
|
||||
let harmony_path = Path::new(&args.harmony_path).try_exists();
|
||||
|
||||
match harmony_path {
|
||||
Ok(_path) => compile_harmony(args.harmony_path.clone()),
|
||||
Err(_) => todo!("implement autodetect code"),
|
||||
}
|
||||
|
||||
match cli_args.command {
|
||||
Commands::Check(args) => {
|
||||
let check_script = match Path::new(&format!("{}/{}", cli_args.harmony_path, "check.sh"))
|
||||
.try_exists()
|
||||
{
|
||||
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");
|
||||
}
|
||||
todo!("implement packaging logic");
|
||||
}
|
||||
Commands::Deploy(args) => {
|
||||
if args.staging {
|
||||
todo!("implement staging deployment");
|
||||
}
|
||||
|
||||
if args.prod {
|
||||
todo!("implement prod deployment");
|
||||
}
|
||||
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"
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
fn compile_harmony(harmony_location: String) {
|
||||
let gctx = cargo::util::context::GlobalContext::default().unwrap();
|
||||
let cargo_exists = gctx.cargo_exe().unwrap().exists();
|
||||
|
||||
if cargo_exists {
|
||||
let _cargo_build = cargo::ops::compile(
|
||||
&cargo::core::Workspace::new(
|
||||
&Path::new(&format!("{}/Cargo.toml", harmony_location))
|
||||
.canonicalize()
|
||||
.unwrap(),
|
||||
&gctx,
|
||||
)
|
||||
.unwrap(),
|
||||
&cargo::ops::CompileOptions::new(&gctx, cargo::core::compiler::CompileMode::Build)
|
||||
.unwrap(),
|
||||
)
|
||||
.expect("build success");
|
||||
return;
|
||||
}
|
||||
|
||||
let _docker_util = docker_utils::DockerUtil::new().expect("Failed to create DockerUtil");
|
||||
|
||||
todo!("implement docker build container");
|
||||
}
|
||||
Reference in New Issue
Block a user