Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix being unable to add versioned dependency #10

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/commands/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ impl AddCommand {
bail!("No exported interfaces found in the component")
};

let mut package_interface_map: HashMap<String, Vec<String>> = HashMap::new();
let mut selected_interfaces: Vec<String> = Vec::new();
let mut package_interface_map: HashMap<_, Vec<String>> = HashMap::new();

// Map interfaces to their respective packages
for (package_name, interface) in exported_interfaces {
Expand All @@ -165,6 +164,8 @@ impl AddCommand {
&package_names,
)?;

let mut selected_interfaces = Vec::new();

for &package_idx in selected_package_indices.iter() {
let package_name = &package_names[package_idx];
let interfaces = package_interface_map.get(package_name).unwrap();
Expand All @@ -190,10 +191,19 @@ impl AddCommand {
)?;

if interface_count > 1 && selected_interface_idx == 0 {
selected_interfaces.push(package_name.clone());
selected_interfaces.push(package_name.to_string());
} else {
let interface_name = &interface_options[selected_interface_idx];
selected_interfaces.push(format!("{}/{}", package_name, interface_name));
let full_itf_name = if let Some(version) = package_name.version.as_ref() {
format!(
"{ns}:{name}/{interface_name}@{version}",
ns = package_name.namespace,
name = package_name.name
)
} else {
format!("{package_name}/{interface_name}")
};
selected_interfaces.push(full_itf_name);
}
}

Expand Down Expand Up @@ -231,7 +241,7 @@ impl AddCommand {

for interface in selected_interfaces {
component.dependencies.inner.insert(
DependencyName::Package(DependencyPackageName::try_from(interface)?),
DependencyName::Package(DependencyPackageName::try_from(interface.clone())?),
component_dependency.clone(),
);
}
Expand Down
5 changes: 4 additions & 1 deletion src/common/interact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ pub fn select_prompt(
Ok(select.interact()?)
}

pub fn select_multiple_prompt(prompt: &str, selection_list: &[String]) -> Result<Vec<usize>> {
pub fn select_multiple_prompt<T: ToString>(
prompt: &str,
selection_list: &[T],
) -> Result<Vec<usize>> {
Ok(MultiSelect::new()
.with_prompt(prompt)
.items(selection_list)
Expand Down
8 changes: 2 additions & 6 deletions src/common/wit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub fn parse_component_bytes(bytes: Vec<u8>) -> Result<(Resolve, PackageId)> {
pub fn get_exported_interfaces(
resolve: &Resolve,
world_id: wit_parser::WorldId,
) -> Vec<(String, String)> {
) -> Vec<(wit_parser::PackageName, String)> {
resolve.worlds[world_id]
.exports
.iter()
Expand All @@ -49,11 +49,7 @@ pub fn get_exported_interfaces(
let i = &resolve.interfaces[*id];
let pkg_id = i.package.unwrap();
let pkg = &resolve.packages[pkg_id];
let mut pkg_name = format!("{}:{}", pkg.name.namespace, pkg.name.name);
if let Some(ver) = &pkg.name.version {
pkg_name.push_str(&format!("@{}", ver));
}
Some((pkg_name, i.name.clone().unwrap_or_default()))
Some((pkg.name.clone(), i.name.clone().unwrap_or_default()))
}
_ => None,
})
Expand Down
Loading