implement build command
This commit is contained in:
parent
6d176ac99f
commit
ee5af8d076
4 changed files with 46 additions and 1 deletions
27
planetwars-cli/src/commands/build.rs
Normal file
27
planetwars-cli/src/commands/build.rs
Normal file
|
@ -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(())
|
||||
}
|
||||
}
|
|
@ -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),
|
||||
}
|
||||
|
|
|
@ -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(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue