- Reworked `dcr.toml` handling: added read, validation, and edit through `core::config`
- `new` and `init` use the new config creation logic
- `build` and `run` now require `dcr.toml` and read `compiler` and `name` from it
This commit is contained in:
2026-02-20 17:54:01 +08:00
parent 06e7af6ab6
commit 5a2025fb80
10 changed files with 312 additions and 50 deletions

View File

@@ -1,5 +1,6 @@
use crate::cli::build::build;
use crate::config::{PROFILE, flags};
use crate::core::config::Config;
use crate::utils::fs::check_dir;
use crate::utils::log::{error, warn};
use crate::utils::text::{BOLD_GREEN, colored};
@@ -14,6 +15,18 @@ pub fn run(args: &[String]) -> i32 {
return 1;
}
let config = match Config::open("./dcr.toml") {
Ok(cfg) => cfg,
Err(_) => {
error("dcr.toml file not found");
return 1;
}
};
let project_name: &str = config
.get("package.name")
.and_then(|v| v.as_str())
.unwrap_or("");
if let Some(first_arg) = args.first() {
if first_arg.starts_with("--") {
let candidate = first_arg.trim_start_matches("--");
@@ -32,11 +45,11 @@ pub fn run(args: &[String]) -> i32 {
let build_status = build(args);
if build_status == 0 {
println!(
"\n {} target/{active_profile}/main",
"\n {} target/{active_profile}/{project_name}",
colored("Running", BOLD_GREEN)
);
println!("--------------------------------");
return Command::new(format!("./target/{active_profile}/main"))
return Command::new(format!("./target/{active_profile}/{project_name}"))
.status()
.map(|status| status.code().unwrap_or(1))
.unwrap_or(1);
@@ -47,7 +60,7 @@ pub fn run(args: &[String]) -> i32 {
.contains(&active_profile)
{
warn("Launch of the latest release");
return Command::new(format!("./target/{active_profile}/main"))
return Command::new(format!("./target/{active_profile}/{project_name}"))
.status()
.map(|status| status.code().unwrap_or(1))
.unwrap_or(1);