diff --git a/moss/src/cli/info.rs b/moss/src/cli/info.rs index 08cb63bd..b3f62d6f 100644 --- a/moss/src/cli/info.rs +++ b/moss/src/cli/info.rs @@ -9,12 +9,14 @@ use futures::StreamExt; use itertools::Itertools; use moss::{ client::{self, Client}, - package::{Flags, Name}, + package::Flags, Package, }; use thiserror::Error; use tui::Stylize; +use super::name_to_provider; + const COLUMN_WIDTH: usize = 20; pub fn command() -> Command { @@ -37,10 +39,10 @@ pub async fn handle(args: &ArgMatches) -> Result<(), Error> { let client = Client::new_for_root(root).await?; for pkg in pkgs { - let nom = Name::from(pkg.clone()); + let lookup = name_to_provider(&pkg); let resolved = client .registry - .by_name(&nom, Flags::AVAILABLE) + .by_provider(&lookup, Flags::AVAILABLE) .collect::>() .await; if resolved.is_empty() { diff --git a/moss/src/cli/install.rs b/moss/src/cli/install.rs index df81b956..59af2d57 100644 --- a/moss/src/cli/install.rs +++ b/moss/src/cli/install.rs @@ -2,17 +2,18 @@ // // SPDX-License-Identifier: MPL-2.0 -use std::{path::PathBuf, str::FromStr}; +use std::path::PathBuf; use clap::{arg, ArgMatches, Command}; use futures::StreamExt; use moss::{ client::{self, Client}, package::Flags, - Provider, }; use thiserror::Error; +use crate::cli::name_to_provider; + pub fn command() -> Command { Command::new("install") .about("Install packages") @@ -36,14 +37,7 @@ pub async fn handle(args: &ArgMatches) -> Result<(), Error> { let mut requested = vec![]; for pkg in pkgs { - let lookup = if pkg.contains('(') { - Provider::from_str(pkg.as_str()).unwrap() - } else { - Provider { - kind: moss::dependency::Kind::PackageName, - name: pkg.clone(), - } - }; + let lookup = name_to_provider(&pkg); let result = client .registry diff --git a/moss/src/cli/mod.rs b/moss/src/cli/mod.rs index c75461fe..c03fb22b 100644 --- a/moss/src/cli/mod.rs +++ b/moss/src/cli/mod.rs @@ -2,9 +2,10 @@ // // SPDX-License-Identifier: MPL-2.0 -use std::path::PathBuf; +use std::{path::PathBuf, str::FromStr}; use clap::{Arg, ArgAction, Command}; +use moss::Provider; use thiserror::Error; mod extract; @@ -16,6 +17,18 @@ mod remove; mod repo; mod version; +/// Convert the name to a lookup provider +pub(crate) fn name_to_provider(name: &str) -> Provider { + if name.contains('(') { + Provider::from_str(name).unwrap() + } else { + Provider { + kind: moss::dependency::Kind::PackageName, + name: name.to_owned(), + } + } +} + /// Generate the CLI command structure fn command() -> Command { Command::new("moss")