Rename crate
This commit is contained in:
63
rust/sea_battle_cli_player/src/cli_args.rs
Normal file
63
rust/sea_battle_cli_player/src/cli_args.rs
Normal file
@@ -0,0 +1,63 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user