diff options
Diffstat (limited to 'planetwars-cli/src/commands')
-rw-r--r-- | planetwars-cli/src/commands/build.rs | 27 | ||||
-rw-r--r-- | planetwars-cli/src/commands/mod.rs | 4 | ||||
-rw-r--r-- | planetwars-cli/src/commands/run_match.rs | 7 |
3 files changed, 37 insertions, 1 deletions
diff --git a/planetwars-cli/src/commands/build.rs b/planetwars-cli/src/commands/build.rs new file mode 100644 index 0000000..1df0bb6 --- /dev/null +++ b/planetwars-cli/src/commands/build.rs @@ -0,0 +1,27 @@ +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/mod.rs b/planetwars-cli/src/commands/mod.rs index db0be21..52fed5c 100644 --- a/planetwars-cli/src/commands/mod.rs +++ b/planetwars-cli/src/commands/mod.rs @@ -1,3 +1,4 @@ +mod build; mod init; mod run_match; mod serve; @@ -21,6 +22,7 @@ impl Cli { Command::Init(command) => command.run().await, Command::RunMatch(command) => command.run().await, Command::Serve(command) => command.run().await, + Command::Build(command) => command.run().await, } } } @@ -33,4 +35,6 @@ enum Command { 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 index 6341b31..868e87c 100644 --- a/planetwars-cli/src/commands/run_match.rs +++ b/planetwars-cli/src/commands/run_match.rs @@ -40,7 +40,12 @@ impl RunMatchCommand { match_runner::run_match(match_config).await; println!("match completed successfully"); // TODO: maybe print the match result as well? - println!("wrote match log to {}", log_path.to_str().unwrap()); + + 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(()) } } |