use clap::{Parser, ValueEnum}; #[derive(Clone, Copy, Debug, ValueEnum)] pub enum TestDevScreen { Popup, Input, Confirm, SelectBotType, SelectPlayMode, SetBoatsLayout, ConfigureGameRules, } #[derive(Parser, Debug)] pub struct CliArgs { /// Upstream server to use #[clap( short, long, value_parser, default_value = "https://seabattleapi.communiquons.org" )] pub remote_server_uri: String, /// Local server listen address #[clap(short, long, default_value = "127.0.0.1:5679")] pub listen_address: String, #[clap(long, value_enum)] pub dev_screen: Option, /// Run as server instead of as client #[clap(long, short)] pub serve: bool, } impl CliArgs { /// Get local listen port pub fn listen_port(&self) -> u16 { self.listen_address .rsplit(':') .next() .expect("Failed to split listen address!") .parse::() .expect("Failed to parse listen port!") } /// Get local server address pub fn local_server_address(&self) -> String { format!("http://localhost:{}", self.listen_port()) } } lazy_static::lazy_static! { static ref ARGS: CliArgs = { CliArgs::parse() }; } /// Get parsed command line arguments pub fn cli_args() -> &'static CliArgs { &ARGS }