Skip to content

Commit 06f1535

Browse files
committed
feat: fix fail and comment removal
1 parent 6a78549 commit 06f1535

File tree

3 files changed

+15
-20
lines changed

3 files changed

+15
-20
lines changed

forc-pkg/src/manifest/dep_modifier.rs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use anyhow::{anyhow, bail, Result};
77
use pkg::manifest::ManifestFile;
88
use std::collections::BTreeMap;
99
use std::fmt;
10-
use std::fs;
1110
use std::path::Path;
1211
use std::path::PathBuf;
1312
use std::str::FromStr;
@@ -116,30 +115,21 @@ pub fn modify_dependencies(opts: ModifyOpts) -> Result<()> {
116115
&opts.ipfs_node.clone().unwrap_or_default(),
117116
);
118117

119-
let new_plan = new_plan.or_else(|e| {
118+
new_plan.or_else(|e| {
120119
std::fs::write(&package_manifest_dir, backup_doc.to_string())
121120
.map_err(|write_err| anyhow!("failed to write toml file: {}", write_err))?;
122121
Err(e)
123122
})?;
124123

125-
let new_lock = Lock::from_graph(new_plan.graph());
126-
127-
new_lock.diff(&old_lock);
128-
129124
if opts.dry_run {
130125
info!("Dry run enabled. toml file not modified.");
131126
std::fs::write(&package_manifest_dir, backup_doc.to_string())?;
132-
return Ok(());
133-
}
134127

135-
let string = toml::ser::to_string_pretty(&new_lock)
136-
.map_err(|e| anyhow!("failed to serialize lock file: {}", e))?;
128+
let string = toml::ser::to_string_pretty(&old_lock)?;
129+
std::fs::write(&lock_path, string)?;
137130

138-
if let Err(e) = fs::write(&lock_path, string) {
139-
std::fs::write(&package_manifest_dir, backup_doc.to_string())
140-
.map_err(|e| anyhow!("failed to write toml file: {}", e))?;
141-
bail!("failed to write lock file: {}", e);
142-
};
131+
return Ok(());
132+
}
143133

144134
Ok(())
145135
}
@@ -309,7 +299,13 @@ impl Section {
309299
dep_data: Dependency,
310300
salt: Option<String>,
311301
) -> Result<()> {
312-
let mut table = Table::new();
302+
let section_name = self.to_string();
303+
304+
if !doc.as_table().contains_key(&section_name) {
305+
doc[&section_name] = Item::Table(Table::new());
306+
}
307+
308+
let table = doc[section_name.as_str()].as_table_mut().unwrap();
313309

314310
match self {
315311
Section::Deps => {
@@ -352,8 +348,6 @@ impl Section {
352348
}
353349
};
354350

355-
doc[&self.to_string()] = Item::Table(table);
356-
357351
Ok(())
358352
}
359353

@@ -430,6 +424,7 @@ fn generate_table(details: &DependencyDetails) -> InlineTable {
430424
mod tests {
431425
use super::*;
432426
use crate::WorkspaceManifestFile;
427+
use std::fs;
433428
use std::str::FromStr;
434429
use tempfile::{tempdir, TempDir};
435430

forc/src/cli/commands/add.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ forc_util::cli_examples! {
1919
#[clap(bin_name = "forc add", version, after_help = help())]
2020
pub struct Command {
2121
/// List of dependencies to add in the format "name[@version]"
22-
#[clap(value_enum, value_name = "DEP_SPEC")]
22+
#[clap(value_enum, value_name = "DEP_SPEC", required = true)]
2323
pub dependencies: Vec<String>,
2424

2525
/// Print the changes that would be made without actually making them

forc/src/cli/commands/remove.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ crate::cli::Opt {
1919
#[clap(bin_name = "forc remove", version, after_help = help())]
2020
pub struct Command {
2121
/// List of dependencies to remove in the format "name[@version]"
22-
#[clap(value_enum, value_name = "DEP_SPEC")]
22+
#[clap(value_enum, value_name = "DEP_SPEC", required = true)]
2323
pub dependencies: Vec<String>,
2424

2525
/// Print the changes that would be made without actually making them

0 commit comments

Comments
 (0)