Skip to content

Commit

Permalink
Added experimental CLI support
Browse files Browse the repository at this point in the history
  • Loading branch information
Bytekeeper committed Mar 9, 2022
1 parent 7a6dd13 commit 916da74
Show file tree
Hide file tree
Showing 5 changed files with 245 additions and 18 deletions.
156 changes: 155 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bwaishotgun"
version = "0.1.0"
version = "0.2.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -12,6 +12,7 @@ registry = "1.2"
anyhow = "1.0"
shared_memory = "0.12"
retry = "1.3"
clap = { version = "3.1", features = ["derive"]}

[profile.release]
lto = true
1 change: 0 additions & 1 deletion build.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
bitsadmin.exe /transfer "Nitekat" "https://www.sscaitournament.com/bot_binary.php?bot=NiteKatT" blub.zip
cargo build --release
releng\7za a -pshotgun -- bwaishotgun.7z target/release/bwaishotgun.exe bots SNP_DirectIP.snp bwheadless.exe game.toml shotgun.toml
releng\7za rn -pshotgun -- bwaishotgun.7z target/release/bwaishotgun.exe BWAIShotgun.exe
63 changes: 63 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
use crate::{BotConfig, GameConfig};
use clap::{ErrorKind, Parser, Subcommand};

#[derive(Subcommand, Debug)]
enum GameType {
/// Host a melee game
Melee {
/// Names of bots to play
bots: Vec<String>,
},
/// You will host a game the bots can join (make sure to select Local PC network)
Human {
/// Names of bots to play
bots: Vec<String>,
},
}

#[derive(Parser, Debug)]
pub struct Cli {
/// Absolute path of map to host
#[clap(short, long)]
map: Option<String>,
#[clap(subcommand)]
game_type: Option<GameType>,
}

pub enum Error {
NoArguments,
ClapError(clap::Error),
}

impl TryFrom<Cli> for GameConfig {
type Error = Error;

fn try_from(cli: Cli) -> Result<Self, Self::Error> {
if cli.map.is_none() && cli.game_type.is_none() {
Err(Error::NoArguments)
} else if cli.map.is_some() != cli.game_type.is_some() {
Err(Error::ClapError(clap::Error::raw(
ErrorKind::DisplayHelpOnMissingArgumentOrSubcommand,
"Either no or all arguments are required. Use '-h' to get help.\n",
)))
} else {
let game_type = match cli.game_type.as_ref().expect("Game Type not set") {
GameType::Melee { bots } | GameType::Human { bots } => crate::GameType::Melee(
bots.iter()
.map(|name| BotConfig {
name: name.to_string(),
player_name: None,
race: None,
})
.collect(),
),
};
Ok(GameConfig {
map: cli.map.unwrap(),
game_name: None,
game_type,
human_host: matches!(cli.game_type.unwrap(), GameType::Human { .. }),
})
}
}
}
Loading

0 comments on commit 916da74

Please sign in to comment.