cargo_run/commands/
init.rs1use std::{fs, io};
4use colored::*;
5use emoji::symbols;
6
7pub fn init_script_file(file_path: Option<&str>) {
20 let file_path = file_path.unwrap_or("Scripts.toml");
21 if fs::metadata(file_path).is_ok() {
22 println!("{} [ {} ] already exists. Do you want to replace it? ({}/{})", symbols::warning::WARNING.glyph, file_path.yellow(), "y".green(), "n".red());
23 let mut input = String::new();
24 io::stdin().read_line(&mut input).expect("Failed to read input");
25 if input.trim().to_lowercase() != "y" {
26 println!("Operation cancelled.");
27 return;
28 }
29 }
30 let default_content = r#"
31[global_env]
32
33[scripts]
34dev = "cargo run"
35build = { command = "cargo build", env = { RUST_LOG = "info" } }
36release = "cargo build --release"
37test = { command = "cargo test", env = { RUST_LOG = "warn" } }
38doc = "cargo doc --no-deps --open"
39"#;
40 fs::write(file_path, default_content).expect("Failed to write Scripts.toml");
41 println!("{} [ {} ] has been created.", symbols::other_symbol::CHECK_MARK.glyph, "Scripts.toml".green());
42}