Added package type filter
This commit is contained in:
parent
6ab97922cb
commit
6b37d007c7
|
@ -24,14 +24,19 @@ 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 {
|
||||
facets.push(format!("[\"project_type:{}\"]", package_type.to_string()));
|
||||
}
|
||||
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,28 @@ pub enum Command {
|
|||
Clean,
|
||||
}
|
||||
|
||||
#[derive(ValueEnum, Clone, Debug)]
|
||||
pub enum PackageType {
|
||||
Fabric,
|
||||
Forge,
|
||||
Quilt,
|
||||
Resource,
|
||||
Pack,
|
||||
}
|
||||
|
||||
impl ToString for PackageType {
|
||||
fn to_string(&self) -> String {
|
||||
match self {
|
||||
PackageType::Fabric => "fabric",
|
||||
PackageType::Forge => "forge",
|
||||
PackageType::Quilt => "quilt",
|
||||
PackageType::Resource => "resourcepack",
|
||||
PackageType::Pack => "modpack",
|
||||
}
|
||||
.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
// TODO move main body argument fields to substruct for ease of moving?
|
||||
#[derive(Parser, Clone, Debug)]
|
||||
#[clap(name = "hopper")]
|
||||
|
|
Loading…
Reference in New Issue