use clap::{Parser, Subcommand};
mod commands;
mod path;
use commands::doc;
use commands::doctor;
use commands::new;
use commands::open;
use commands::run;
use commands::setup;
use commands::setup_emu;
use commands::setup_web;
use commands::uninstall;
use commands::web_export;
use commands::web_server;
rust_i18n::i18n!("locales");
#[derive(Parser)]
#[command(name = "sgdkx")]
#[command(version = "0.1.3")]
struct Cli {
#[command(subcommand)]
command: Option<Commands>,
}
#[derive(Subcommand)]
enum Commands {
Setup(setup::Args),
SetupEmu(setup_emu::Args),
New(new::Args),
Run(run::Args),
SetupWeb(setup_web::Args),
WebExport(web_export::Args),
WebServer(web_server::Args),
Doc,
Open(open::Args),
Uninstall,
}
fn main() {
init_locale();
let cli = Cli::parse();
match &cli.command {
Some(cmd) => match cmd {
Commands::Setup(args) => {
setup::run(&args);
}
Commands::SetupEmu(args) => {
setup_emu::run(&args);
}
Commands::New(args) => {
new::run(&args);
}
Commands::Run(args) => {
run::run(args);
}
Commands::Uninstall => {
uninstall::run();
}
Commands::Doc => {
doc::run();
}
Commands::WebExport(args) => {
web_export::run(args);
}
Commands::WebServer(args) => {
web_server::run(args);
}
Commands::Open(args) => {
open::run(args);
}
Commands::SetupWeb(args) => {
setup_web::run(args);
}
},
None => {
doctor::run();
}
}
}
fn init_locale() {
let locale = std::env::var("LANG")
.or_else(|_| std::env::var("LC_ALL"))
.unwrap_or_else(|_| "en".to_string());
if locale.starts_with("ja") {
rust_i18n::set_locale("ja");
} else {
rust_i18n::set_locale("en");
}
}