diff --git a/src/commands/add.rs b/src/commands/add.rs index a5c0b44..586add2 100644 --- a/src/commands/add.rs +++ b/src/commands/add.rs @@ -147,8 +147,7 @@ impl AddCommand { bail!("No exported interfaces found in the component") }; - let mut package_interface_map: HashMap> = HashMap::new(); - let mut selected_interfaces: Vec = Vec::new(); + let mut package_interface_map: HashMap<_, Vec> = HashMap::new(); // Map interfaces to their respective packages for (package_name, interface) in exported_interfaces { @@ -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(); @@ -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); } } @@ -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(), ); } diff --git a/src/common/interact.rs b/src/common/interact.rs index 1cc59d5..3feb48a 100644 --- a/src/common/interact.rs +++ b/src/common/interact.rs @@ -14,7 +14,10 @@ pub fn select_prompt( Ok(select.interact()?) } -pub fn select_multiple_prompt(prompt: &str, selection_list: &[String]) -> Result> { +pub fn select_multiple_prompt( + prompt: &str, + selection_list: &[T], +) -> Result> { Ok(MultiSelect::new() .with_prompt(prompt) .items(selection_list) diff --git a/src/common/wit.rs b/src/common/wit.rs index 22dbb72..c34c63c 100644 --- a/src/common/wit.rs +++ b/src/common/wit.rs @@ -40,7 +40,7 @@ pub fn parse_component_bytes(bytes: Vec) -> 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() @@ -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, })