crossbundle_tools/commands/common/
create_project.rs

1use crate::error::*;
2use std::path::Path;
3use std::process::Command;
4
5/// Creates a new project.
6/// Runs `cargo generate ...` with given args.
7pub fn create_project(
8    current_dir: &Path,
9    name: &str,
10    git: &str,
11    branch: &Option<String>,
12) -> Result<()> {
13    let mut cargo_generate = Command::new("cargo");
14    cargo_generate
15        .current_dir(current_dir)
16        .arg("generate")
17        .arg("--git")
18        .arg(git)
19        .arg("--name")
20        .arg(name);
21    if let Some(branch) = branch {
22        cargo_generate.arg("--branch").arg(branch);
23    };
24    cargo_generate.output_err(true)?;
25    Ok(())
26}
27
28/// Checks if `cargo-generate` is installed in the system.
29pub fn check_cargo_generate() -> bool {
30    Command::new("cargo")
31        .arg("generate")
32        .arg("-V")
33        .output()
34        .map(|s| s.status.success())
35        .unwrap_or(false)
36}