Skip to content

Commit

Permalink
Use own parser for removing dev-dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Nov 20, 2019
1 parent 1f9ddee commit c771836
Show file tree
Hide file tree
Showing 5 changed files with 256 additions and 136 deletions.
118 changes: 0 additions & 118 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ serde_derive = "1.0.102"
serde_json = "1.0.41"
termcolor = "1.0.5"
toml = "0.5.5"
toml_edit = "0.1.5"

[dev-dependencies]
easy-ext = "0.1.6"
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod cli;
mod manifest;
mod metadata;
mod process;
mod remove_dev_deps;
mod restore;

use std::{env, ffi::OsString, fs, path::Path};
Expand Down Expand Up @@ -132,7 +133,7 @@ fn no_dev_deps(
restore: &Restore,
) -> Result<()> {
if args.no_dev_deps || args.remove_dev_deps {
let new = manifest.remove_dev_deps()?;
let new = manifest.remove_dev_deps();
let mut handle = restore.set_manifest(&manifest);

fs::write(&package.manifest_path, new).with_context(|| {
Expand Down
18 changes: 2 additions & 16 deletions src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,8 @@ impl Manifest {
self.package.as_ref().unwrap().publish == false
}

pub(crate) fn remove_dev_deps(&self) -> Result<String> {
let mut doc: toml_edit::Document = self.raw.parse()?;
remove_key_and_target_key(doc.as_table_mut(), "dev-dependencies");
Ok(doc.to_string_in_original_order())
}
}

fn remove_key_and_target_key(table: &mut toml_edit::Table, key: &str) {
table.remove(key);
if let Some(table) = table.entry("target").as_table_mut() {
// `toml_edit::Table` does not have `.iter_mut()`, so collect keys.
for k in table.iter().map(|(key, _)| key.to_string()).collect::<Vec<_>>() {
if let Some(table) = table.entry(&k).as_table_mut() {
table.remove(key);
}
}
pub(crate) fn remove_dev_deps(&self) -> String {
super::remove_dev_deps::remove_dev_deps(&self.raw)
}
}

Expand Down
Loading

0 comments on commit c771836

Please sign in to comment.