From ff861095e37ef5210806bfa36a16e5c415ea44d7 Mon Sep 17 00:00:00 2001 From: Klesti Selimaj Date: Thu, 2 Jul 2026 20:38:01 +0200 Subject: [PATCH] Using toml for init --- Cargo.lock | 1 + Cargo.toml | 1 + src/main.mist | 10 ++++++---- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4ada694..0cc26df 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -519,6 +519,7 @@ version = "0.3.7-alpha.1" dependencies = [ "mist-analyzer", "mist-api", + "toml", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 8b37fa1..8a33dff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ include = [ [dependencies] mist-analyzer = { workspace = true } mist-api = { workspace = true } +toml = "1.1.2" [workspace] members = [ diff --git a/src/main.mist b/src/main.mist index 8cb02ac..cc01ecf 100644 --- a/src/main.mist +++ b/src/main.mist @@ -99,12 +99,14 @@ void init_project(Vec mut args) void inject_mist_target(bool is_lib) { String toml_content = fs::read_to_string("Cargo.toml").expect("Failed to read Cargo.toml"); - str& inject = if is_lib { - "\n[lib]\nname = \"my_lib\"\npath = \".mist/src/lib.rs\"\n" + toml::Value parsed = toml::from_str(&toml_content).expect("Failed to parse Cargo.toml"); + String name = parsed["package"]["name"].as_str().expect("Missing package.name in Cargo.toml").to_string(); + String inject = if is_lib { + format!("\n[lib]\nname = \"{name}\"\npath = \".mist/src/lib.rs\"\n") } else { - "\n[[bin]]\nname = \"my_bin\"\npath = \".mist/src/main.rs\"\n" + format!("\n[[bin]]\nname = \"{name}\"\npath = \".mist/src/main.rs\"\n") }; - fs::write("Cargo.toml", toml_content + inject).expect("Failed to inject to Cargo.toml"); + fs::write("Cargo.toml", toml_content + &inject).expect("Failed to inject to Cargo.toml"); } void add_mist_toml(bool is_lib)