mirror of
https://github.com/LordMZTE/mcstat.git
synced 2024-05-04 22:01:11 +02:00
remove port argument
port will now be parsed from the ip argument
This commit is contained in:
parent
d0f9ed1afe
commit
a934e610ec
|
@ -2,16 +2,10 @@ name: "mcstat"
|
|||
about: "queries information about a minecraft server"
|
||||
args:
|
||||
- ip:
|
||||
help: "the ip of the server to ping"
|
||||
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
|
||||
- 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"
|
||||
|
|
33
src/main.rs
33
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,28 +19,17 @@ async fn main() -> Result<()> {
|
|||
let matches = App::from_yaml(yaml).get_matches();
|
||||
|
||||
// region Network
|
||||
let config = ConnectionConfig::build(
|
||||
matches
|
||||
let mut ip = matches
|
||||
.value_of("ip")
|
||||
.context(ARGUMENT_FAIL_MESSAGE)?
|
||||
.to_owned(),
|
||||
)
|
||||
.splitn(2, ':');
|
||||
|
||||
let config = ConnectionConfig::build(ip.next().context("invalid ip")?.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")?,
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue