~starkingdoms/starkingdoms

ref: fe41c97bea51ac5122cf948b660f7c64c5bc90f6 starkingdoms/crates/unified/src/cli.rs -rw-r--r-- 1.2 KiB
fe41c97b — core chore(netcode-rewrite): reorganize dependencies 29 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#[cfg(not(any(feature = "native", feature = "wasm")))]
compile_error!("You need to enable one of native, wasm features");
#[cfg(all(feature = "native", feature = "wasm"))]
compile_error!("You cannot enable both native and wasm features");

pub enum StkArgs {
    Play,
}

#[cfg(not(target_arch = "wasm32"))]
pub fn parse_args() -> StkArgs {
    let mut pargs = pico_args::Arguments::from_env();

    if pargs.contains(["-h", "--help"]) {
        print_help();
        std::process::exit(0);
    }

    if pargs.contains(["-v", "--version"]) {
        println!("{}", env!("CARGO_PKG_VERSION"));
        std::process::exit(0);
    }

    let subcommand = pargs.subcommand().unwrap();

    match subcommand.as_deref() {
        None | Some("play") => StkArgs::Play,
        Some(unknown) => {
            eprintln!("unknown subcommand: {unknown}");
            eprintln!("-h, --help for help");
            std::process::exit(1);
        }
    }
}

fn print_help() {
    println!("\
USAGE:
    starkingdoms [FLAGS] [subcommand]

FLAGS:
    -h, --help        Prints help information
    -v, --version     Prints version information

SUBCOMMANDS:
    play              Run the game (default)");
}