remove port argument
port will now be parsed from the ip argument
This commit is contained in:
parent
d0f9ed1afe
commit
a934e610ec
2 changed files with 82 additions and 99 deletions
126
src/args.yml
126
src/args.yml
|
@ -1,72 +1,66 @@
|
|||
name: "mcstat"
|
||||
about: "queries information about a minecraft server"
|
||||
args:
|
||||
- ip:
|
||||
help: "the ip of the server to ping"
|
||||
takes_value: true
|
||||
index: 1
|
||||
required: true
|
||||
- port:
|
||||
help: "the port of the server"
|
||||
long: "port"
|
||||
short: p
|
||||
default_value: "25565"
|
||||
takes_value: true
|
||||
- protocol-version:
|
||||
long: "protocol"
|
||||
help: "the protocol version to use"
|
||||
default_value: "751"
|
||||
takes_value: true
|
||||
- timeout:
|
||||
long: "timeout"
|
||||
short: t
|
||||
help: "the time before the server ping times out in milliseconds"
|
||||
takes_value: true
|
||||
default_value: "500"
|
||||
- raw:
|
||||
short: r
|
||||
help: "if supplied, the raw json response from the server will be printed"
|
||||
- mods:
|
||||
short: m
|
||||
help: "if supplied, a mod list will be printed"
|
||||
- modversions:
|
||||
short: v
|
||||
help: "if supplied, mods will also have their version info printed"
|
||||
requires: "mods"
|
||||
- channels:
|
||||
long: "channels"
|
||||
help: "displays forge mod channels if the server sends them"
|
||||
- ip:
|
||||
help: "the ip of the server to ping. you may also specify the port, if it is not specified or invalid it will default to 25565"
|
||||
takes_value: true
|
||||
index: 1
|
||||
required: true
|
||||
- protocol-version:
|
||||
long: "protocol"
|
||||
help: "the protocol version to use"
|
||||
default_value: "751"
|
||||
takes_value: true
|
||||
- timeout:
|
||||
long: "timeout"
|
||||
short: t
|
||||
help: "the time before the server ping times out in milliseconds"
|
||||
takes_value: true
|
||||
default_value: "500"
|
||||
- raw:
|
||||
short: r
|
||||
help: "if supplied, the raw json response from the server will be printed"
|
||||
- mods:
|
||||
short: m
|
||||
help: "if supplied, a mod list will be printed"
|
||||
- modversions:
|
||||
short: v
|
||||
help: "if supplied, mods will also have their version info printed"
|
||||
requires: "mods"
|
||||
- channels:
|
||||
long: "channels"
|
||||
help: "displays forge mod channels if the server sends them"
|
||||
|
||||
# IMAGE ARGS
|
||||
# TODO due to a bug in clap, the image argument is always required because size has a default value
|
||||
- image:
|
||||
short: "i"
|
||||
help: "if the server's favicon should be printed as ASCII art"
|
||||
required: false
|
||||
- color:
|
||||
short: "c"
|
||||
help: "if the favicon image should be printed with ANSI color formatting or monochrome"
|
||||
- size:
|
||||
short: "s"
|
||||
help: "the size of the image"
|
||||
takes_value: true
|
||||
default_value: "16"
|
||||
- deep:
|
||||
short: "d"
|
||||
help: "if provided the ascii image will have more different characters"
|
||||
- invert:
|
||||
short: "n"
|
||||
help: "inverts the ascii image thickness"
|
||||
# IMAGE ARGS
|
||||
# TODO due to a bug in clap, the image argument is always required because size has a default value
|
||||
- image:
|
||||
short: "i"
|
||||
help: "if the server's favicon should be printed as ASCII art"
|
||||
required: false
|
||||
- color:
|
||||
short: "c"
|
||||
help: "if the favicon image should be printed with ANSI color formatting or monochrome"
|
||||
- size:
|
||||
short: "s"
|
||||
help: "the size of the image"
|
||||
takes_value: true
|
||||
default_value: "16"
|
||||
- deep:
|
||||
short: "d"
|
||||
help: "if provided the ascii image will have more different characters"
|
||||
- invert:
|
||||
short: "n"
|
||||
help: "inverts the ascii image thickness"
|
||||
|
||||
groups:
|
||||
- img-flags:
|
||||
# TODO uncomment once bug is fixed
|
||||
# requires:
|
||||
# - image
|
||||
multiple: true
|
||||
required: false
|
||||
args:
|
||||
- color
|
||||
- size
|
||||
- deep
|
||||
- invert
|
||||
- img-flags:
|
||||
# TODO uncomment once bug is fixed
|
||||
# requires:
|
||||
# - image
|
||||
multiple: true
|
||||
required: false
|
||||
args:
|
||||
- color
|
||||
- size
|
||||
- deep
|
||||
- invert
|
||||
|
|
55
src/main.rs
55
src/main.rs
|
@ -2,13 +2,13 @@ use std::io::Cursor;
|
|||
use time::Duration;
|
||||
use tokio::time;
|
||||
|
||||
use anyhow::{Context, Result, anyhow};
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use asciify::AsciiBuilder;
|
||||
use async_minecraft_ping::{ConnectionConfig, ServerDescription, StatusResponse};
|
||||
use clap::{App, load_yaml};
|
||||
use clap::{load_yaml, App};
|
||||
use image::ImageFormat;
|
||||
use itertools::Itertools;
|
||||
use mcstat::{AsciiConfig, get_table, none_if_empty, print_table, remove_formatting};
|
||||
use mcstat::{get_table, none_if_empty, print_table, remove_formatting, AsciiConfig};
|
||||
use termcolor::{Buffer, BufferWriter, ColorChoice, WriteColor};
|
||||
|
||||
/// this message is used if getting a value from the arguments fails
|
||||
|
@ -19,36 +19,25 @@ async fn main() -> Result<()> {
|
|||
let matches = App::from_yaml(yaml).get_matches();
|
||||
|
||||
// region Network
|
||||
let config = ConnectionConfig::build(
|
||||
matches
|
||||
.value_of("ip")
|
||||
.context(ARGUMENT_FAIL_MESSAGE)?
|
||||
.to_owned(),
|
||||
)
|
||||
.with_port(
|
||||
matches
|
||||
.value_of("port")
|
||||
.context(ARGUMENT_FAIL_MESSAGE)?
|
||||
.parse()
|
||||
.context("invalid port")
|
||||
.and_then(|p| {
|
||||
// the port must be above 0
|
||||
if p > 0 {
|
||||
Ok(p)
|
||||
} else {
|
||||
// this error will be overriden anyways
|
||||
Err(anyhow!(""))
|
||||
}
|
||||
})
|
||||
.context("invalid port")?,
|
||||
)
|
||||
.with_protocol_version(
|
||||
matches
|
||||
.value_of("protocol-version")
|
||||
.context(ARGUMENT_FAIL_MESSAGE)?
|
||||
.parse()
|
||||
.context("invalid protocol version")?,
|
||||
);
|
||||
let mut ip = matches
|
||||
.value_of("ip")
|
||||
.context(ARGUMENT_FAIL_MESSAGE)?
|
||||
.splitn(2, ':');
|
||||
|
||||
let config = ConnectionConfig::build(ip.next().context("invalid ip")?.to_owned())
|
||||
.with_port(
|
||||
ip.next()
|
||||
.map_or(Err(()), |p| p.parse::<u16>().map_err(|_| ()))
|
||||
.and_then(|p| if p > 0 { Ok(p) } else { Err(()) })
|
||||
.unwrap_or(25565),
|
||||
)
|
||||
.with_protocol_version(
|
||||
matches
|
||||
.value_of("protocol-version")
|
||||
.context(ARGUMENT_FAIL_MESSAGE)?
|
||||
.parse()
|
||||
.context("invalid protocol version")?,
|
||||
);
|
||||
|
||||
// create timeout for server connection
|
||||
let mut timeout = time::delay_for(Duration::from_millis(
|
||||
|
|
Loading…
Reference in a new issue