diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2022-07-21 19:19:40 +0200 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2022-07-21 19:19:40 +0200 |
commit | c6293d8e328bb96c368921fe922092d4f27f0bc9 (patch) | |
tree | 1c374345ba911b79167ae70a654dd0618efa9446 /planetwars-cli/src/commands | |
parent | 31f8271db6735a1c7abea4d93bb3b8d7a3ce4628 (diff) | |
download | planetwars.dev-c6293d8e328bb96c368921fe922092d4f27f0bc9.tar.xz planetwars.dev-c6293d8e328bb96c368921fe922092d4f27f0bc9.zip |
delete old planetwars-cli code
Diffstat (limited to 'planetwars-cli/src/commands')
-rw-r--r-- | planetwars-cli/src/commands/build.rs | 27 | ||||
-rw-r--r-- | planetwars-cli/src/commands/init.rs | 38 | ||||
-rw-r--r-- | planetwars-cli/src/commands/mod.rs | 40 | ||||
-rw-r--r-- | planetwars-cli/src/commands/run_match.rs | 51 | ||||
-rw-r--r-- | planetwars-cli/src/commands/serve.rs | 17 |
5 files changed, 0 insertions, 173 deletions
diff --git a/planetwars-cli/src/commands/build.rs b/planetwars-cli/src/commands/build.rs deleted file mode 100644 index 1df0bb6..0000000 --- a/planetwars-cli/src/commands/build.rs +++ /dev/null @@ -1,27 +0,0 @@ -use clap::Parser; -use std::io; -use tokio::process; - -use crate::workspace::Workspace; - -#[derive(Parser)] -pub struct BuildCommand { - /// Name of the bot to build - bot: String, -} - -impl BuildCommand { - pub async fn run(self) -> io::Result<()> { - let workspace = Workspace::open_current_dir()?; - let bot = workspace.get_bot(&self.bot)?; - if let Some(argv) = bot.config.get_build_argv() { - process::Command::new(&argv[0]) - .args(&argv[1..]) - .current_dir(&bot.path) - .spawn()? - .wait() - .await?; - } - Ok(()) - } -} diff --git a/planetwars-cli/src/commands/init.rs b/planetwars-cli/src/commands/init.rs deleted file mode 100644 index c95626b..0000000 --- a/planetwars-cli/src/commands/init.rs +++ /dev/null @@ -1,38 +0,0 @@ -use std::path::PathBuf; - -use clap::Parser; -use futures::io; - -#[derive(Parser)] -pub struct InitCommand { - /// workspace root directory - path: String, -} - -macro_rules! copy_asset { - ($path:expr, $file_name:literal) => { - ::std::fs::write( - $path.join($file_name), - include_bytes!(concat!("../../assets/", $file_name)), - )?; - }; -} - -impl InitCommand { - pub async fn run(self) -> io::Result<()> { - let path = PathBuf::from(&self.path); - - // create directories - std::fs::create_dir_all(&path)?; - std::fs::create_dir(path.join("maps"))?; - std::fs::create_dir(path.join("matches"))?; - std::fs::create_dir_all(path.join("bots/simplebot"))?; - - // create files - copy_asset!(path, "pw_workspace.toml"); - copy_asset!(path.join("maps"), "hex.json"); - copy_asset!(path.join("bots/"), "simplebot/botconfig.toml"); - copy_asset!(path.join("bots/"), "simplebot/simplebot.py"); - Ok(()) - } -} diff --git a/planetwars-cli/src/commands/mod.rs b/planetwars-cli/src/commands/mod.rs deleted file mode 100644 index 52fed5c..0000000 --- a/planetwars-cli/src/commands/mod.rs +++ /dev/null @@ -1,40 +0,0 @@ -mod build; -mod init; -mod run_match; -mod serve; - -use clap::{Parser, Subcommand}; -use std::io; - -#[derive(Parser)] -#[clap(name = "pwcli")] -#[clap(author, version, about)] -pub struct Cli { - #[clap(subcommand)] - command: Command, -} - -impl Cli { - pub async fn run() -> io::Result<()> { - let cli = Self::parse(); - - match cli.command { - Command::Init(command) => command.run().await, - Command::RunMatch(command) => command.run().await, - Command::Serve(command) => command.run().await, - Command::Build(command) => command.run().await, - } - } -} - -#[derive(Subcommand)] -enum Command { - /// Initialize a new workspace - Init(init::InitCommand), - /// Run a match - RunMatch(run_match::RunMatchCommand), - /// Host local webserver - Serve(serve::ServeCommand), - /// Run build command for a bot - Build(build::BuildCommand), -} diff --git a/planetwars-cli/src/commands/run_match.rs b/planetwars-cli/src/commands/run_match.rs deleted file mode 100644 index 03868ae..0000000 --- a/planetwars-cli/src/commands/run_match.rs +++ /dev/null @@ -1,51 +0,0 @@ -use std::io; - -use clap::Parser; -use planetwars_matchrunner::{run_match, MatchConfig, MatchPlayer}; - -use crate::workspace::Workspace; -#[derive(Parser)] -pub struct RunMatchCommand { - /// map name - map: String, - /// bot names - bots: Vec<String>, -} - -impl RunMatchCommand { - pub async fn run(self) -> io::Result<()> { - let workspace = Workspace::open_current_dir()?; - - let map_path = workspace.map_path(&self.map); - let timestamp = chrono::Local::now().format("%Y-%m-%d-%H-%M-%S"); - let log_path = workspace.match_path(&format!("{}-{}", &self.map, ×tamp)); - - let mut players = Vec::new(); - for bot_name in &self.bots { - let bot = workspace.get_bot(&bot_name)?; - players.push(MatchPlayer { - name: bot_name.clone(), - path: bot.path.clone(), - argv: bot.config.get_run_argv(), - }); - } - - let match_config = MatchConfig { - map_name: self.map, - map_path, - log_path: log_path.clone(), - players, - }; - - run_match(match_config).await; - println!("match completed successfully"); - // TODO: maybe print the match result as well? - - let relative_path = match log_path.strip_prefix(&workspace.root_path) { - Ok(path) => path.to_str().unwrap(), - Err(_) => log_path.to_str().unwrap(), - }; - println!("wrote match log to {}", relative_path); - Ok(()) - } -} diff --git a/planetwars-cli/src/commands/serve.rs b/planetwars-cli/src/commands/serve.rs deleted file mode 100644 index aa8d149..0000000 --- a/planetwars-cli/src/commands/serve.rs +++ /dev/null @@ -1,17 +0,0 @@ -use std::io; - -use clap::Parser; - -use crate::web; -use crate::workspace::Workspace; - -#[derive(Parser)] -pub struct ServeCommand; - -impl ServeCommand { - pub async fn run(self) -> io::Result<()> { - let workspace = Workspace::open_current_dir()?; - web::run(workspace).await; - Ok(()) - } -} |