diff --git a/Cargo.lock b/Cargo.lock index 0b4381092..62e726d76 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -99,7 +99,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be69f70ef5497dd6ab331a50bd95c6ac6b8f7f17a7967838332743fbd58dc3b5" dependencies = [ "argh_shared", - "heck 0.3.3", + "heck", "proc-macro2", "quote", "syn", @@ -340,7 +340,7 @@ dependencies = [ "anyhow", "argh", "cargo_metadata", - "heck 0.3.3", + "heck", "quill-plugin-format", ] @@ -405,36 +405,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "clap" -version = "3.0.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a30c3bf9ff12dfe5dae53f0a96e0febcd18420d1c0e7fad77796d9d5c4b5375" -dependencies = [ - "atty", - "bitflags", - "clap_derive", - "indexmap", - "lazy_static", - "os_str_bytes", - "strsim", - "termcolor", - "textwrap", -] - -[[package]] -name = "clap_derive" -version = "3.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "517358c28fcef6607bf6f76108e02afad7e82297d132a6b846dcc1fc3efcd153" -dependencies = [ - "heck 0.4.0", - "proc-macro-error", - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "cmake" version = "0.1.48" @@ -806,7 +776,7 @@ version = "0.1.0" dependencies = [ "anyhow", "bincode", - "heck 0.3.3", + "heck", "indexmap", "maplit", "once_cell", @@ -1185,12 +1155,6 @@ dependencies = [ "unicode-segmentation", ] -[[package]] -name = "heck" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" - [[package]] name = "hecs" version = "0.3.2" @@ -1781,15 +1745,6 @@ dependencies = [ "syn", ] -[[package]] -name = "os_str_bytes" -version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64" -dependencies = [ - "memchr", -] - [[package]] name = "parking" version = "2.0.0" @@ -2004,7 +1959,7 @@ name = "proxy" version = "0.1.0" dependencies = [ "anyhow", - "clap", + "argh", "colored", "feather-protocol", "fern", @@ -2787,7 +2742,7 @@ version = "0.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d06aaeeee809dbc59eb4556183dd927df67db1540de5be8d3ec0b6636358a5ec" dependencies = [ - "heck 0.3.3", + "heck", "proc-macro2", "quote", "syn", @@ -2865,21 +2820,6 @@ 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 = "textwrap" -version = "0.14.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80" - [[package]] name = "thiserror" version = "1.0.30" @@ -3567,15 +3507,6 @@ 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" diff --git a/proxy/Cargo.toml b/proxy/Cargo.toml index e739e7555..6a68c12a1 100644 --- a/proxy/Cargo.toml +++ b/proxy/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [dependencies] feather-protocol = { path = "../feather/protocol" } -clap = { version = "3.0.5", features = ["derive"] } +argh = "0.1" pretty-hex = "0.2.1" log = "0.4.14" fern = "0.6.0" diff --git a/proxy/src/main.rs b/proxy/src/main.rs index 161e747c5..670328edd 100644 --- a/proxy/src/main.rs +++ b/proxy/src/main.rs @@ -2,11 +2,10 @@ use std::fmt::{Display, Formatter}; use std::io::{Read, Write}; use std::net::SocketAddr; use std::net::{TcpListener, TcpStream}; -use std::num::ParseIntError; use std::sync::{Arc, Mutex}; use anyhow::Context; -use clap::{ArgEnum, Parser}; +use argh::FromArgs; use colored::Colorize; use log::{Level, LevelFilter}; use time::macros::format_description; @@ -20,48 +19,53 @@ use feather_protocol::{ }; /// A simple proxy server that logs transmitted packets -#[derive(Parser)] -#[clap(about, version)] +#[derive(FromArgs)] struct Args { - /// The Minecraft server address (ip:port) - #[clap(short = 'a', long)] + /// the Minecraft server address (ip:port) + #[argh(option, short = 'a')] server_address: SocketAddr, - /// The address that the proxy should listen on (ip:port) - #[clap(short, long)] + /// the address that the proxy should listen on (ip:port) + #[argh(option, short = 'p')] proxy_address: SocketAddr, - /// Only log clientside/serverside packets - #[clap(arg_enum, short, long, default_value_t)] + /// only log clientside/serverside packets + #[argh(option, short = 's', default = "ConnectionSide::Both")] side: ConnectionSide, - /// Show the contents of the packets. `-vv` will also display hexdump - #[clap(short, long, parse(from_occurrences))] + /// show the contents of the packets. `-v1` will also display hexdump + #[argh(option, short = 'v')] verbose: usize, - /// Don't log packets with the specified IDs (hexadecimal, comma-separated) - #[clap(short, long, use_delimiter = true, parse(try_from_str = parse_hex), conflicts_with = "whitelist")] + /// don't log packets with the specified IDs (hexadecimal, comma-separated) + #[argh(option, short = 'w', from_str_fn(idlist))] blacklist: Option>, - /// Log only packets with the specified IDs (hexadecimal, comma-separated) - #[clap(short, long, use_delimiter = true, parse(try_from_str = parse_hex), conflicts_with = "blacklist")] + /// log only packets with the specified IDs (hexadecimal, comma-separated) + #[argh(option, short = 'w', from_str_fn(idlist))] whitelist: Option>, } - -fn parse_hex(src: &str) -> Result { - u32::from_str_radix(src, 16) +fn idlist(src: &str) -> Result, String> { + src.split(',') + .map(|n| u32::from_str_radix(n, 16).map_err(|e| e.to_string())) + .collect() } -#[derive(ArgEnum, Copy, Clone)] +#[derive(Copy, Clone)] enum ConnectionSide { Client, Server, Both, } - -impl Default for ConnectionSide { - fn default() -> Self { - ConnectionSide::Both +impl core::str::FromStr for ConnectionSide { + type Err = &'static str; + fn from_str(s: &str) -> Result { + match s { + "client" => Ok(Self::Client), + "server" => Ok(Self::Server), + "both" => Ok(Self::Both), + _ => Err("expected 'client', 'server', or 'both'"), + } } } fn main() { - let args: Args = Args::parse(); + let args: Args = argh::from_env(); fern::Dispatch::new() .format(|out, message, record| { let level_string = match record.level() {