use anyhow::Result;
use clap::{Parser, Subcommand};
use mc_snap::commands;
#[derive(Parser)]
#[command(name = "mc-snap", version, about = "Declarative Minecraft server management")]
struct Cli {
#[command(subcommand)]
cmd: Cmd,
}
#[derive(Subcommand)]
enum Cmd {
Init {
#[arg(long)]
non_interactive: bool,
#[arg(long, value_name = "PATH", num_args = 0..=1, default_missing_value = ".")]
detect: Option<String>,
#[arg(long)]
force: bool,
#[arg(long)]
no_mod_resolve: bool,
},
Install,
Validate,
Doctor,
Start {
#[arg(long)]
detach: bool,
},
Stop,
Restart,
Status,
Logs {
#[arg(short, long)]
follow: bool,
},
Console {
command: Vec<String>,
},
Pack {
#[arg(short, long, default_value = "mc-snap-bundle.zip")]
out: String,
},
Unpack {
bundle: String,
},
Update {
#[arg(long)]
to: String,
#[arg(long)]
skip_missing: bool,
#[arg(short = 'y', long)]
yes: bool,
#[arg(long)]
loader: Option<String>,
},
Revert {
id: Option<String>,
#[arg(long)]
list: bool,
},
Check {
#[arg(long)]
to: String,
},
Updatable {
#[arg(long)]
to: Option<String>,
},
Search,
}
#[tokio::main]
async fn main() -> Result<()> {
tracing_subscriber::fmt()
.with_env_filter(
tracing_subscriber::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info")),
)
.with_target(false)
.init();
let cli = Cli::parse();
match cli.cmd {
Cmd::Init { non_interactive, detect, force, no_mod_resolve } => {
commands::init::run(non_interactive, detect, force, no_mod_resolve).await
}
Cmd::Install => commands::install::run().await,
Cmd::Validate => commands::validate::run().await,
Cmd::Doctor => commands::doctor::run().await,
Cmd::Start { detach } => commands::start::run(detach).await,
Cmd::Stop => commands::stop::run().await,
Cmd::Restart => commands::restart::run().await,
Cmd::Status => commands::status::run().await,
Cmd::Logs { follow } => commands::logs::run(follow).await,
Cmd::Console { command } => commands::console::run(command).await,
Cmd::Pack { out } => commands::pack::run(&out).await,
Cmd::Unpack { bundle } => commands::unpack::run(&bundle).await,
Cmd::Update { to, skip_missing, yes, loader } => {
commands::update::run(&to, skip_missing, yes, loader).await
}
Cmd::Revert { id, list } => commands::revert::run(id, list).await,
Cmd::Check { to } => commands::check::run(&to).await,
Cmd::Updatable { to } => commands::updatable::run(to).await,
Cmd::Search => commands::search::run().await,
}
}