Skip to content

Commit

Permalink
wup
Browse files Browse the repository at this point in the history
Signed-off-by: Oliver Tale-Yazdi <[email protected]>
  • Loading branch information
ggwpez committed Oct 25, 2023
1 parent 4eeaa3d commit 7d9a6c4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 16 deletions.
38 changes: 28 additions & 10 deletions src/autofix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,10 +472,7 @@ impl AutoFixer {
cargo_metadata::semver::VersionReq::parse(as_str).expect("Is semver");
let mut table = InlineTable::new();
table.insert("workspace", Value::Boolean(Formatted::new(true)));

if default_feats {
table.insert("default-features", Value::Boolean(Formatted::new(true)));
}
table.insert("default-features", Value::Boolean(Formatted::new(default_feats)));
table.set_dotted(false);

*dep = Item::Value(Value::InlineTable(table));
Expand All @@ -485,9 +482,7 @@ impl AutoFixer {
}
as_table.remove("version");
as_table.insert("workspace", Value::Boolean(Formatted::new(true)));
if default_feats {
as_table.insert("default-features", Value::Boolean(Formatted::new(true)));
}
as_table.insert("default-features", Value::Boolean(Formatted::new(default_feats)));
} else {
unreachable!("Unknown kind of dependency: {:?}", dep);
}
Expand All @@ -496,10 +491,33 @@ impl AutoFixer {

pub fn add_workspace_dep(
&mut self,
_dep: &Dependency,
_default_feats: bool,
dep: &Dependency,
default_feats: bool,
) -> Result<(), String> {
panic!("todo");
let doc: &mut Document = self.doc.as_mut().unwrap();

if !doc.contains_table("workspace") {
return Err("No workspace table".into())
}
let workspace = doc["workspace"].as_table_mut().unwrap();

if !workspace.contains_table("dependencies") {
workspace.insert("dependencies", table());
}

let deps = workspace["dependencies"].as_table_mut().unwrap();

if deps.contains_key(&dep.name) {
return Err("Dependency already exists in the workspace".into())
}

let mut t = InlineTable::new();
t.insert("version", Value::String(Formatted::new(dep.req.to_string())));
t.insert("default-features", Value::Boolean(Formatted::new(default_feats)));

deps.insert(&dep.name, Item::Value(Value::InlineTable(t)));

Ok(())
}

pub fn modified(&self) -> bool {
Expand Down
15 changes: 9 additions & 6 deletions src/cmd/transpose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,12 @@ impl LiftToWorkspaceCmd {
));
}

let _hint = format!("cargo upgrade -p {}@version", &self.dependency);
let hint = format!("cargo upgrade -p {}@version", &self.dependency);
panic!(
"\nFound {} different versions of '{}' in the workspace:\n{err}",
"\nFound {} different versions of '{}' in the workspace:\n\n{err}\nHint: {}\n",
versions.len(),
&self.dependency,
g.bold(&hint),
);
}

Expand Down Expand Up @@ -154,9 +155,11 @@ impl LiftToWorkspaceCmd {
}

// Now create fixer for the root package
//let mut fixer =
// AutoFixer::from_manifest(&meta.workspace_root.into_std_path_buf()).unwrap();
// fixer.add_workspace_dep(&found_dep.unwrap(), false);
//fixer.save().unwrap();
let root_manifest_path = meta.workspace_root.join("Cargo.toml");
let mut fixer =
AutoFixer::from_manifest(&root_manifest_path.into_std_path_buf()).unwrap();
let dep = by_version.values().next().unwrap().first().unwrap().1.clone();
fixer.add_workspace_dep(&dep, false).unwrap();
fixer.save().unwrap();
}
}

0 comments on commit 7d9a6c4

Please sign in to comment.