Merge pull request 'Add support for filtering plugins and resource packs' (#14) from PluginResourcePackSupport into main
Reviewed-on: #14
This commit is contained in:
commit
716579f824
|
@ -1,5 +1,5 @@
|
|||
use crate::api::{ModInfo, ModResult, ModVersion, ModVersionFile, SearchResponse};
|
||||
use crate::config::{Args, Config, SearchArgs};
|
||||
use crate::config::{Args, Config, PackageType, SearchArgs};
|
||||
use futures_util::StreamExt;
|
||||
use log::*;
|
||||
use std::cmp::min;
|
||||
|
@ -24,14 +24,34 @@ impl HopperClient {
|
|||
let url = format!("https://{}/v2/search", self.config.upstream.server_address);
|
||||
|
||||
let mut params = vec![("query", search_args.package_name.to_owned())];
|
||||
let mut facets: Vec<String> = Vec::new();
|
||||
if let Some(versions) = &search_args.version {
|
||||
let versions_facets = versions
|
||||
.iter()
|
||||
.map(|e| format!("[\"versions:{}\"]", e))
|
||||
.collect::<Vec<String>>()
|
||||
.join(",");
|
||||
params.push(("facets", format!("[{}]", versions_facets)));
|
||||
facets.push(format!("{}", versions_facets));
|
||||
}
|
||||
if let Some(package_type) = &search_args.package_type {
|
||||
let package_type_facet = match package_type {
|
||||
PackageType::Fabric => "[\"categories:fabric\"],[\"project_type:mod\"]",
|
||||
PackageType::Forge => "[\"categories:forge\"],[\"project_type:mod\"]",
|
||||
PackageType::Quilt => "[\"categories:quilt\"],[\"project_type:mod\"]",
|
||||
PackageType::Resource => "[\"project_type:resourcepack\"]",
|
||||
PackageType::FabricPack => "[\"project_type:modpack\"],[\"categories:fabric\"]",
|
||||
PackageType::ForgePack => "[\"project_type:modpack\"],[\"categories:forge\"]",
|
||||
PackageType::QuiltPack => "[\"project_type:modpack\"],[\"categories:quilt\"]",
|
||||
PackageType::BukkitPlugin => "[\"project_type:mod\"],[\"categories:bukkit\"]",
|
||||
PackageType::PaperPlugin => "[\"project_type:mod\"],[\"categories:paper\"]",
|
||||
PackageType::PurpurPlugin => "[\"project_type:mod\"],[\"categories:purpur\"]",
|
||||
PackageType::SpigotPlugin => "[\"project_type:mod\"],[\"categories:spigot\"]",
|
||||
PackageType::SpongePlugin => "[\"project_type:mod\"],[\"categories:sponge\"]",
|
||||
}
|
||||
.to_string();
|
||||
facets.push(package_type_facet);
|
||||
}
|
||||
params.push(("facets", format!("[{}]", facets.join(","))));
|
||||
|
||||
let url = reqwest::Url::parse_with_params(url.as_str(), ¶ms)?;
|
||||
info!("GET {}", url);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use clap::{Parser, Subcommand};
|
||||
use clap::{Parser, Subcommand, ValueEnum};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::path::PathBuf;
|
||||
|
||||
|
@ -7,6 +7,10 @@ use std::path::PathBuf;
|
|||
pub struct SearchArgs {
|
||||
pub package_name: String,
|
||||
|
||||
/// Type of package to use
|
||||
#[clap(short, long, value_enum)]
|
||||
pub package_type: Option<PackageType>,
|
||||
|
||||
/// Restricts the target Minecraft version
|
||||
#[clap(short, long)]
|
||||
pub version: Option<Vec<String>>,
|
||||
|
@ -26,6 +30,22 @@ pub enum Command {
|
|||
Clean,
|
||||
}
|
||||
|
||||
#[derive(ValueEnum, Clone, Debug)]
|
||||
pub enum PackageType {
|
||||
Fabric,
|
||||
Forge,
|
||||
Quilt,
|
||||
Resource,
|
||||
FabricPack,
|
||||
ForgePack,
|
||||
QuiltPack,
|
||||
BukkitPlugin,
|
||||
PaperPlugin,
|
||||
PurpurPlugin,
|
||||
SpigotPlugin,
|
||||
SpongePlugin,
|
||||
}
|
||||
|
||||
// TODO move main body argument fields to substruct for ease of moving?
|
||||
#[derive(Parser, Clone, Debug)]
|
||||
#[clap(name = "hopper")]
|
||||
|
|
Loading…
Reference in New Issue