in tools/hakari/src/cli_ops/workspace_ops.rs [82:124]
fn apply(&self, workspace_root: &Utf8Path) -> Result<(), ApplyError> {
match self {
WorkspaceOp::NewCrate {
crate_path,
files,
root_files,
} => {
Self::create_new_crate(workspace_root, crate_path, files)?;
// Now that the crate has been created, we can canonicalize it.
let crate_path = canonical_rel_path(crate_path, workspace_root)?;
for (rel_path, contents) in root_files {
let abs_path = workspace_root.join(rel_path.as_ref());
let parent = abs_path.parent().expect("abs path should have a parent");
std::fs::create_dir_all(&parent).map_err(|err| {
ApplyError::io("error creating directories", &parent, err)
})?;
write_contents(contents, &abs_path)?;
}
Self::add_to_root_toml(workspace_root, &crate_path)
}
WorkspaceOp::AddDependency {
name,
crate_path,
version,
dep_format,
add_to,
} => {
let crate_path = canonical_rel_path(crate_path, workspace_root)?;
for package in add_to.packages(DependencyDirection::Reverse) {
Self::add_to_cargo_toml(name, version, &crate_path, *dep_format, package)?;
}
Ok(())
}
WorkspaceOp::RemoveDependency { name, remove_from } => {
for package in remove_from.packages(DependencyDirection::Reverse) {
Self::remove_from_cargo_toml(name, package)?;
}
Ok(())
}
}
}