diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2021-12-28 19:28:19 +0100 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2021-12-28 19:28:19 +0100 |
commit | ee5af8d07625bfc7ad11b842b3941bb095aa6a6e (patch) | |
tree | b1f21f06a6a45b4b36cfcfa50ea5bd16a3132670 /planetwars-cli/src | |
parent | 6d176ac99fb096034ff5406700a7921dab48c24f (diff) | |
download | planetwars.dev-ee5af8d07625bfc7ad11b842b3941bb095aa6a6e.tar.xz planetwars.dev-ee5af8d07625bfc7ad11b842b3941bb095aa6a6e.zip |
implement build command
Diffstat (limited to 'planetwars-cli/src')
-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 | ||||
-rw-r--r-- | planetwars-cli/src/workspace/bot.rs | 9 |
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.") + }) + } } |