diff --git a/rocks-bin/src/main.rs b/rocks-bin/src/main.rs index 96f309a5..9db5e5e8 100644 --- a/rocks-bin/src/main.rs +++ b/rocks-bin/src/main.rs @@ -1,6 +1,7 @@ use std::path::PathBuf; use clap::{Parser, Subcommand}; +use rocks_lib::config::Config; mod download; mod search; @@ -122,9 +123,11 @@ enum Commands { async fn main() { let cli = Cli::parse(); + let config = Config::default(); + match cli.command { Some(command) => match command { - Commands::Search(search_data) => search::search(search_data).await.unwrap(), + Commands::Search(search_data) => search::search(search_data, &config).await.unwrap(), Commands::Download(download_data) => download::download(download_data).await.unwrap(), _ => unimplemented!(), }, diff --git a/rocks-bin/src/search.rs b/rocks-bin/src/search.rs index ef9a3e2e..45d3c92b 100644 --- a/rocks-bin/src/search.rs +++ b/rocks-bin/src/search.rs @@ -3,7 +3,10 @@ use clap::Args; use itertools::Itertools; use text_trees::{FormatCharacters, StringTreeNode, TreeFormatting}; -use rocks_lib::manifest::{manifest_from_server, ManifestMetadata}; +use rocks_lib::{ + config::Config, + manifest::{manifest_from_server, ManifestMetadata}, +}; #[derive(Args)] pub struct Search { @@ -17,16 +20,21 @@ pub struct Search { porcelain: bool, } -pub async fn search(data: Search) -> Result<()> { +pub async fn search(data: Search, config: &Config) -> Result<()> { let formatting = TreeFormatting::dir_tree(FormatCharacters::box_chars()); // TODO(vhyrro): Pull in global configuration in the form of a second parameter (including which server to use for the manifest). - let manifest = manifest_from_server("https://luarocks.org".into(), None, None).await?; + let manifest = manifest_from_server(config.server.to_owned(), &config).await?; let metadata = ManifestMetadata::new(&manifest)?; - for key in metadata.repository.keys().collect::>() { + for key in metadata + .repository + .keys() + .sorted() + .collect::>() + { // TODO(vhyrro): Use fuzzy matching here instead. if key.contains(&data.name) { let versions = metadata.repository[key] @@ -35,10 +43,7 @@ pub async fn search(data: Search) -> Result<()> { if data.porcelain { versions.for_each(|version| { - println!( - "{} {} {} {}", - key, version, "src|rockspec", "https://luarocks.org/" - ) + println!("{} {} {} {}", key, version, "src|rockspec", config.server) }); } else { let mut tree = StringTreeNode::new(key.to_owned());