use {
crate::{module, module::ModuleOptions, utils, Error, Result},
cargo_toml::Workspace,
std::env,
};
pub fn create_module_in_workspace(
path: &str,
options: ModuleOptions,
workspace: Workspace,
) -> Result<()> {
let path_segments: Vec<&str> = path.split("::").collect();
if path_segments.iter().any(|s| s.is_empty()) || path_segments.len() < 2 {
return Error::other("Bad module path");
}
let target_member = path_segments[0];
if workspace.members.contains(&target_member.to_owned()) {
let cd = env::current_dir()?;
env::set_current_dir(target_member)?;
module::create_module(utils::get_root_file_name()?, &path_segments[1..], options)?;
env::set_current_dir(cd)?;
Ok(())
} else {
Error::other("package not present in workspace `Cargo.toml`. consider adding it there")
}
}