Add option to restrict Minecraft version
Add log and env_logger
This commit is contained in:
parent
af3f60be5d
commit
30e8c782df
|
@ -2,6 +2,15 @@
|
|||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "0.7.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ansi_term"
|
||||
version = "0.11.0"
|
||||
|
@ -181,6 +190,19 @@ dependencies = [
|
|||
"cfg-if 1.0.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "env_logger"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3"
|
||||
dependencies = [
|
||||
"atty",
|
||||
"humantime",
|
||||
"log",
|
||||
"regex",
|
||||
"termcolor",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fnv"
|
||||
version = "1.0.7"
|
||||
|
@ -326,8 +348,10 @@ dependencies = [
|
|||
"confy",
|
||||
"console",
|
||||
"dialoguer",
|
||||
"env_logger",
|
||||
"futures-util",
|
||||
"indicatif",
|
||||
"log",
|
||||
"reqwest",
|
||||
"serde",
|
||||
"serde_json",
|
||||
|
@ -369,6 +393,12 @@ version = "1.0.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
|
||||
|
||||
[[package]]
|
||||
name = "humantime"
|
||||
version = "2.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
|
||||
|
||||
[[package]]
|
||||
name = "hyper"
|
||||
version = "0.14.15"
|
||||
|
@ -783,6 +813,8 @@ version = "1.5.4"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
|
@ -1010,6 +1042,15 @@ dependencies = [
|
|||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termcolor"
|
||||
version = "1.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4"
|
||||
dependencies = [
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "terminal_size"
|
||||
version = "0.1.17"
|
||||
|
@ -1311,6 +1352,15 @@ version = "0.4.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-util"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
|
|
|
@ -9,8 +9,10 @@ anyhow = "1.0"
|
|||
confy = "0.4"
|
||||
console = "0.15.0"
|
||||
dialoguer = "0.9.0"
|
||||
env_logger = "0.9.0"
|
||||
futures-util = "0.3.18"
|
||||
indicatif = "0.15.0"
|
||||
log = "0.4.14"
|
||||
reqwest = { version = "0.11", features = ["json", "stream"] }
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
|
|
14
src/main.rs
14
src/main.rs
|
@ -1,4 +1,5 @@
|
|||
use console::style;
|
||||
use log::*;
|
||||
use futures_util::StreamExt;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::cmp::min;
|
||||
|
@ -11,6 +12,10 @@ use structopt::StructOpt;
|
|||
#[derive(StructOpt, Clone, Debug)]
|
||||
struct SearchArgs {
|
||||
package_name: String,
|
||||
|
||||
/// Restricts the target Minecraft version
|
||||
#[structopt(short, long)]
|
||||
version: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
// TODO use ColoredHelp by default?
|
||||
|
@ -220,8 +225,14 @@ struct ModVersionFile {
|
|||
async fn search_mods(ctx: &AppContext, search_args: &SearchArgs) -> anyhow::Result<SearchResponse> {
|
||||
let client = reqwest::Client::new();
|
||||
let url = format!("https://{}/api/v1/mod", ctx.config.upstream.server_address);
|
||||
let params = [("query", search_args.package_name.as_str())];
|
||||
|
||||
let mut params = vec![("query", search_args.package_name.to_owned())];
|
||||
if let Some(versions) = &search_args.version {
|
||||
params.push(("versions", versions.join(",")));
|
||||
}
|
||||
|
||||
let url = reqwest::Url::parse_with_params(url.as_str(), ¶ms)?;
|
||||
info!("GET {}", url);
|
||||
let response = client
|
||||
.get(url)
|
||||
.send()
|
||||
|
@ -385,6 +396,7 @@ async fn cmd_get(ctx: &AppContext, search_args: SearchArgs) -> anyhow::Result<()
|
|||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
env_logger::init();
|
||||
let args = Args::from_args();
|
||||
let config = args.load_config()?;
|
||||
let ctx = AppContext { args, config };
|
||||
|
|
Loading…
Reference in New Issue