aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--planetwars-cli/src/commands/build.rs27
-rw-r--r--planetwars-cli/src/commands/mod.rs4
-rw-r--r--planetwars-cli/src/commands/run_match.rs7
-rw-r--r--planetwars-cli/src/workspace/bot.rs9
4 files changed, 46 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(())
}
}
diff --git a/planetwars-cli/src/workspace/bot.rs b/planetwars-cli/src/workspace/bot.rs
index cc88076..a0ecb90 100644
--- a/planetwars-cli/src/workspace/bot.rs
+++ b/planetwars-cli/src/workspace/bot.rs
@@ -33,9 +33,18 @@ pub struct BotConfig {
}
impl BotConfig {
+ // TODO: these commands should not be here
pub fn get_run_argv(&self) -> Vec<String> {
// TODO: proper error handling
shlex::split(&self.run_command)
.expect("Failed to parse bot run command. Check for unterminated quotes.")
}
+
+ pub fn get_build_argv(&self) -> Option<Vec<String>> {
+ // TODO: proper error handling
+ self.build_command.as_ref().map(|cmd| {
+ shlex::split(cmd)
+ .expect("Failed to parse bot build command. Check for unterminated quotes.")
+ })
+ }
}