Pierre Hubert
9a38a634eb
All checks were successful
continuous-integration/drone/push Build is passing
64 lines
1.4 KiB
Rust
64 lines
1.4 KiB
Rust
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<TestDevScreen>,
|
|
|
|
/// 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::<u16>()
|
|
.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
|
|
}
|