~starkingdoms/starkingdoms

ref: d2b8956323d8e82903824637cdcfb2f978dd94e9 starkingdoms/crates/xtask/src/util.rs -rw-r--r-- 852 bytes
d2b89563 — core chore: please thy lord clippy 16 days ago
                                                                                
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
28
29
30
use std::path::{Path, PathBuf};
use std::process::exit;
use colored::Colorize;

pub fn workspace_dir() -> PathBuf {
    let output = std::process::Command::new(env!("CARGO"))
        .arg("locate-project")
        .arg("--workspace")
        .arg("--message-format=plain")
        .output()
        .unwrap()
        .stdout;
    let cargo_path = Path::new(std::str::from_utf8(&output).unwrap().trim());
    cargo_path.parent().unwrap().to_path_buf()
}

pub fn cargo(cmd: String) {
    println!("{} cargo {}", "[cargo]".bold().cyan(), cmd);
    let mut output = std::process::Command::new(env!("CARGO"));

    for command in cmd.split(" ") {
        output.arg(command);
    }
    let output = output.spawn().unwrap().wait().unwrap();

    if !output.success() {
        println!("{}", "============ TASK FAILED".bold().red());
        exit(1);
    }
}