#[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 {
Client {
server: String,
},
#[cfg(not(target_arch = "wasm32"))]
Server {
bind_to: std::net::SocketAddr,
with_client: bool
},
}
#[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 Some(subcommand) = pargs.subcommand().unwrap() else {
eprintln!("a subcommand is required");
print_help();
std::process::exit(1);
};
match subcommand.as_str() {
"client" => {
StkArgs::Client {
server: pargs.value_from_str(["-s", "--server"]).unwrap(),
}
},
#[cfg(not(target_arch = "wasm32"))]
"server" => {
StkArgs::Server {
bind_to: pargs.value_from_str(["-b", "--bind-to"]).unwrap(),
with_client: pargs.contains("--with-client"),
}
},
unknown => {
eprintln!("unknown subcommand: {unknown} (is that feature supported on this platform?)");
eprintln!("-h, --help for help");
std::process::exit(1);
}
}
}
fn print_help() {
println!("\
USAGE:
starkingdoms [FLAGS] <subcommand> [<args>...]
FLAGS:
-h, --help Prints help information
-v, --version Prints version information
SUBCOMMANDS:
");
println!(" client Run the client (see CLIENT for options)");
if cfg!(not(target_arch = "wasm32")) {
println!(" server Run the server (see SERVER for options)");
}
println!("\n");
println!("\
CLIENT:
-s, --server <URL> WebSocket URL to connect to
");
if cfg!(not(target_arch = "wasm32")) {
print!("\
SERVER:
-b, --bind-to <IP:PORT> Socket address to bind to
--with-client Start a client connected to this server
\n");
}
}