make it actually check folder properly

This commit is contained in:
tahahawa 2025-06-10 16:27:53 -04:00
parent b6f252e344
commit edf96780e7
3 changed files with 58 additions and 58 deletions

1
Cargo.lock generated
View File

@ -2840,6 +2840,7 @@ dependencies = [
"docker_utils", "docker_utils",
"env_logger", "env_logger",
"inquire", "inquire",
"log",
"tokio", "tokio",
] ]

View File

@ -11,5 +11,6 @@ clap = { version = "4.5.35", features = ["derive"] }
inquire.workspace = true inquire.workspace = true
tokio.workspace = true tokio.workspace = true
env_logger.workspace = true env_logger.workspace = true
log.workspace = true
cargo = "0.88.0" cargo = "0.88.0"
docker_utils = "0.2.3" docker_utils = "0.2.3"

View File

@ -4,19 +4,19 @@ use std::process::Command;
use clap::builder::ArgPredicate; use clap::builder::ArgPredicate;
use clap::{Args, Parser, Subcommand}; use clap::{Args, Parser, Subcommand};
use inquire::Confirm; use inquire::Confirm;
use log::{debug, info, warn};
#[derive(Parser)] #[derive(Parser)]
#[command(version, about, long_about = None)] #[command(version, about, long_about = None, flatten_help = true, propagate_version = true)]
#[command(propagate_version = true)]
struct GlobalArgs { struct GlobalArgs {
#[arg(long, default_value = "./harmony")] #[arg(long, default_value = "harmony")]
harmony_path: String, harmony_path: String,
#[command(subcommand)] #[command(subcommand)]
command: Commands, command: Option<Commands>,
} }
#[derive(Subcommand)] #[derive(Subcommand, Clone, Debug)]
enum Commands { enum Commands {
Check(CheckArgs), Check(CheckArgs),
Package(PackageArgs), Package(PackageArgs),
@ -24,21 +24,19 @@ enum Commands {
All(AllArgs), All(AllArgs),
} }
#[derive(Args)] #[derive(Args, Clone, Debug)]
struct CheckArgs { struct CheckArgs {
#[arg(long, default_value = "check.sh")] #[arg(long, default_value = "check.sh")]
check_script_path: String, check_script_path: String,
} }
#[derive(Args)] #[derive(Args, Clone, Debug)]
struct PackageArgs { struct PackageArgs {
#[arg(long, default_value_t = false)]
package: bool,
#[arg(long, default_value_t = false)] #[arg(long, default_value_t = false)]
publish: bool, publish: bool,
} }
#[derive(Args)] #[derive(Args, Clone, Debug)]
struct DeployArgs { struct DeployArgs {
#[arg(long, default_value_t = false)] #[arg(long, default_value_t = false)]
staging: bool, staging: bool,
@ -50,40 +48,38 @@ struct DeployArgs {
smoke_test: bool, smoke_test: bool,
} }
#[derive(Args)] #[derive(Args, Clone, Debug)]
struct AllArgs { struct AllArgs {
#[arg(long, default_value = "check.sh")] #[command(flatten)]
check_script_path: String, check: CheckArgs,
#[arg(long, default_value_t = false)] #[command(flatten)]
package: bool, package: PackageArgs,
#[arg(long, default_value_t = false)] #[command(flatten)]
publish: bool, deploy: 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,
} }
fn main() { fn main() {
env_logger::init();
let cli_args = GlobalArgs::parse(); 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 { match harmony_path {
Ok(_path) => compile_harmony(args.harmony_path.clone()), true => compile_harmony(cli_args.harmony_path.clone()),
Err(_) => todo!("implement autodetect code"), false => todo!("implement autodetect code"),
} }
match cli_args.command { match cli_args.command {
Some(command) => match command {
Commands::Check(args) => { Commands::Check(args) => {
let check_script = match Path::new(&format!("{}/{}", cli_args.harmony_path, "check.sh")) let check_script = match Path::new(&format!(
"{}/{}",
cli_args.harmony_path, args.check_script_path
))
.try_exists() .try_exists()
{ {
Ok(path) => path, Ok(path) => path,
@ -115,6 +111,8 @@ fn main() {
Commands::All(args) => todo!( Commands::All(args) => todo!(
"take all previous match arms and turn them into separate functions, and call them all one after the other" "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( &cargo::core::Workspace::new(
&Path::new(&format!("{}/Cargo.toml", harmony_location)) &Path::new(&format!("{}/Cargo.toml", harmony_location))
.canonicalize() .canonicalize()
.unwrap(), .expect("Couldn't find Cargo.toml in harmony dir"),
&gctx, &gctx,
) )
.unwrap(), .unwrap(),
&cargo::ops::CompileOptions::new(&gctx, cargo::core::compiler::CompileMode::Build) &cargo::ops::CompileOptions::new(&gctx, cargo::core::compiler::CompileMode::Build)
.unwrap(), .unwrap(),
) )
.expect("build success"); .expect("build didn't go successfully");
return; return;
} }