use anyhow::Result;
use clap::Parser;
mod commands;
mod template;
mod utils;
#[derive(Debug, Parser)]
#[clap(version)]
pub struct Opts {
#[clap(subcommand)]
pub command: Command,
}
#[derive(Debug, Parser)]
pub enum Command {
Build {
name: String,
},
Serve {
name: String,
#[clap(short, long)]
address: Option<String>,
#[clap(short, long)]
port: Option<u16>,
#[clap(long)]
protocol: Option<String>,
},
Test,
Deploy {
name: String,
project: String,
},
Clean,
Init {
name: String,
#[clap(short, long)]
dry_run: bool,
},
New {
name: String,
#[clap(short, long)]
dry_run: bool,
},
}
fn process_command(opts: Opts) -> Result<()> {
match &opts.command {
Command::Build { name } => {
commands::build::run(name);
Ok(())
}
Command::Serve {
name,
address,
port,
protocol,
} => {
commands::serve::run(name, address.as_deref(), port.as_ref(), protocol.as_deref());
Ok(())
}
Command::Test => {
commands::test::run();
Ok(())
}
Command::Clean => {
commands::clean::run();
Ok(())
}
Command::Init { name, dry_run } => {
commands::init::run(name, *dry_run);
Ok(())
}
Command::New { name, dry_run } => {
commands::new::run(name, *dry_run);
Ok(())
}
Command::Deploy { name, project } => {
commands::deploy::run(name, project);
Ok(())
}
}
}
pub fn entry(opts: Opts) -> Result<()> {
process_command(opts)
}