use clap::{Parser, Subcommand};
use color_eyre::Result;
mod commands;
mod config;
mod constants;
mod docker;
mod env_builder;
mod error;
mod logging;
mod process;
mod validation;
use commands::{config::ConfigAction, contract::ContractAction, devnet::DevnetAction};
use config::BackendType as ConfigBackendType;
use hylix::logging::log_error;
#[derive(Parser)]
#[command(
name = "hy",
version,
about,
long_about = None,
arg_required_else_help = true
)]
struct Cli {
#[command(subcommand)]
command: Commands,
#[arg(short, long, global = true)]
verbose: bool,
#[arg(short, long, global = true)]
quiet: bool,
}
#[derive(Subcommand)]
enum Commands {
#[command(alias = "n")]
New {
name: String,
#[arg(long, value_enum)]
backend: Option<ConfigBackendType>,
},
#[command(alias = "b")]
Build {
#[arg(long)]
clean: bool,
#[arg(long)]
front: bool,
},
#[command(alias = "t")]
Test {
#[arg(long)]
keep_alive: bool,
#[arg(long)]
e2e: bool,
#[arg(long)]
unit: bool,
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
extra_args: Vec<String>,
},
#[command(alias = "r")]
Run {
#[arg(long)]
testnet: bool,
#[arg(long)]
watch: bool,
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
extra_args: Vec<String>,
},
#[command(alias = "d")]
Devnet {
#[command(subcommand)]
action: DevnetAction,
},
#[command(alias = "c")]
Contract {
#[command(subcommand)]
action: ContractAction,
},
Clean,
Config {
#[command(subcommand)]
action: ConfigAction,
},
}
#[tokio::main]
async fn main() -> Result<()> {
color_eyre::install()?;
let cli = Cli::parse();
logging::init_logging(cli.verbose, cli.quiet)?;
let result = match cli.command {
Commands::New { name, backend } => commands::new::execute(name, backend).await,
Commands::Build { clean, front } => commands::build::execute(clean, front).await,
Commands::Test {
keep_alive,
e2e,
unit,
extra_args,
} => commands::test::execute(keep_alive, e2e, unit, extra_args).await,
Commands::Run {
testnet,
watch,
extra_args,
} => commands::run::execute(testnet, watch, extra_args).await,
Commands::Devnet { action } => commands::devnet::execute(action).await,
Commands::Clean => commands::clean::execute().await,
Commands::Config { action } => commands::config::execute(action).await,
Commands::Contract { action } => commands::contract::execute(action).await,
};
if let Err(err) = result {
log_error(&format!("{err:#}"));
std::process::exit(1);
}
Ok(())
}