aboutsummaryrefslogtreecommitdiff
path: root/planetwars-cli/src/commands/build.rs
blob: 1df0bb682bd474017a1c39a5c006aa87da9d2645 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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(())
    }
}