diff --git a/src/cli/commands/add.rs b/src/cli/commands/add.rs index 583fe9d..72c9937 100644 --- a/src/cli/commands/add.rs +++ b/src/cli/commands/add.rs @@ -151,20 +151,20 @@ impl AddCommand { .unwrap_or(url.path.to_string()), }); + let field = &mut manifest[dependency_key] + .or_insert(toml_edit::Item::Table(toml_edit::Table::new()))[&alias]; + match specifier { DependencySpecifiers::Pesde(spec) => { - manifest[dependency_key][&alias]["name"] = - toml_edit::value(spec.name.clone().to_string()); - manifest[dependency_key][&alias]["version"] = - toml_edit::value(format!("^{}", version_id.version())); + field["name"] = toml_edit::value(spec.name.clone().to_string()); + field["version"] = toml_edit::value(format!("^{}", version_id.version())); if *version_id.target() != project_target { - manifest[dependency_key][&alias]["target"] = - toml_edit::value(version_id.target().to_string()); + field["target"] = toml_edit::value(version_id.target().to_string()); } if let Some(index) = spec.index.filter(|i| i != DEFAULT_INDEX_NAME) { - manifest[dependency_key][&alias]["index"] = toml_edit::value(index); + field["index"] = toml_edit::value(index); } println!( @@ -177,13 +177,11 @@ impl AddCommand { } #[cfg(feature = "wally-compat")] DependencySpecifiers::Wally(spec) => { - manifest[dependency_key][&alias]["wally"] = - toml_edit::value(spec.name.clone().to_string()); - manifest[dependency_key][&alias]["version"] = - toml_edit::value(format!("^{}", version_id.version())); + field["wally"] = toml_edit::value(spec.name.clone().to_string()); + field["version"] = toml_edit::value(format!("^{}", version_id.version())); if let Some(index) = spec.index.filter(|i| i != DEFAULT_INDEX_NAME) { - manifest[dependency_key][&alias]["index"] = toml_edit::value(index); + field["index"] = toml_edit::value(index); } println!( @@ -194,9 +192,8 @@ impl AddCommand { ); } DependencySpecifiers::Git(spec) => { - manifest[dependency_key][&alias]["repo"] = - toml_edit::value(spec.repo.to_bstring().to_string()); - manifest[dependency_key][&alias]["rev"] = toml_edit::value(spec.rev.clone()); + field["repo"] = toml_edit::value(spec.repo.to_bstring().to_string()); + field["rev"] = toml_edit::value(spec.rev.clone()); println!("added git {}#{} to {}", spec.repo, spec.rev, dependency_key); } diff --git a/src/cli/commands/init.rs b/src/cli/commands/init.rs index ec60a58..239c477 100644 --- a/src/cli/commands/init.rs +++ b/src/cli/commands/init.rs @@ -122,7 +122,8 @@ impl InitCommand { .prompt() .unwrap(); - manifest["target"]["environment"] = toml_edit::value(target_env); + manifest["target"].or_insert(toml_edit::Item::Table(toml_edit::Table::new())) + ["environment"] = toml_edit::value(target_env); if target_env == "roblox" || inquire::Confirm::new(&format!( @@ -153,20 +154,23 @@ impl InitCommand { ) .context("failed to write sourcemap generator script file")?; - manifest["scripts"][&ScriptName::RobloxSyncConfigGenerator.to_string()] = + let scripts = + manifest["scripts"].or_insert(toml_edit::Item::Table(toml_edit::Table::new())); + + scripts[&ScriptName::RobloxSyncConfigGenerator.to_string()] = toml_edit::value(format!( concat!(".", env!("CARGO_PKG_NAME"), "/{}.luau"), ScriptName::RobloxSyncConfigGenerator )); - manifest["scripts"][&ScriptName::SourcemapGenerator.to_string()] = - toml_edit::value(format!( - concat!(".", env!("CARGO_PKG_NAME"), "/{}.luau"), - ScriptName::SourcemapGenerator - )); + scripts[&ScriptName::SourcemapGenerator.to_string()] = toml_edit::value(format!( + concat!(".", env!("CARGO_PKG_NAME"), "/{}.luau"), + ScriptName::SourcemapGenerator + )); } - manifest["indices"][DEFAULT_INDEX_NAME] = + manifest["indices"].or_insert(toml_edit::Item::Table(toml_edit::Table::new())) + [DEFAULT_INDEX_NAME] = toml_edit::value(read_config()?.default_index.to_bstring().to_string()); project.write_manifest(manifest.to_string())?; diff --git a/src/cli/commands/patch_commit.rs b/src/cli/commands/patch_commit.rs index 2152885..ab2a4fe 100644 --- a/src/cli/commands/patch_commit.rs +++ b/src/cli/commands/patch_commit.rs @@ -67,7 +67,8 @@ impl PatchCommitCommand { std::fs::write(&patch_file, patch).context("failed to write patch file")?; - manifest["patches"][&name.to_string()][&version_id.to_string()] = + manifest["patches"].or_insert(toml_edit::Item::Table(toml_edit::Table::new())) + [&name.to_string()][&version_id.to_string()] = toml_edit::value(format!("patches/{patch_file_name}")); project