Using toml for init

This commit is contained in:
2026-07-02 20:38:01 +02:00
parent 744adeb068
commit ff861095e3
3 changed files with 8 additions and 4 deletions
Generated
+1
View File
@@ -519,6 +519,7 @@ version = "0.3.7-alpha.1"
dependencies = [ dependencies = [
"mist-analyzer", "mist-analyzer",
"mist-api", "mist-api",
"toml",
] ]
[[package]] [[package]]
+1
View File
@@ -18,6 +18,7 @@ include = [
[dependencies] [dependencies]
mist-analyzer = { workspace = true } mist-analyzer = { workspace = true }
mist-api = { workspace = true } mist-api = { workspace = true }
toml = "1.1.2"
[workspace] [workspace]
members = [ members = [
+6 -4
View File
@@ -99,12 +99,14 @@ void init_project(Vec<String> mut args)
void inject_mist_target(bool is_lib) void inject_mist_target(bool is_lib)
{ {
String toml_content = fs::read_to_string("Cargo.toml").expect("Failed to read Cargo.toml"); String toml_content = fs::read_to_string("Cargo.toml").expect("Failed to read Cargo.toml");
str& inject = if is_lib { toml::Value parsed = toml::from_str(&toml_content).expect("Failed to parse Cargo.toml");
"\n[lib]\nname = \"my_lib\"\npath = \".mist/src/lib.rs\"\n" 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 { } 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) void add_mist_toml(bool is_lib)