1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use clap::{App, AppSettings, Arg, ArgMatches};
use std::env;
pub struct ArgParser {}
const VERSION: &str = env!("CARGO_PKG_VERSION");
impl ArgParser {
pub fn parse(args: env::ArgsOs) -> ArgMatches<'static> {
App::new("netspeed")
.version(VERSION)
.about("Measure tcp throughput")
.global_setting(AppSettings::ColorAuto)
.global_setting(AppSettings::ColoredHelp)
.global_setting(AppSettings::VersionlessSubcommands)
.arg(
Arg::with_name("verbose")
.long("verbose")
.short("v")
.multiple(true)
.global(true)
.help("Logging verbose"),
)
.arg(
Arg::with_name("address")
.long("addr")
.alias("address")
.short("a")
.help("Remote server address")
.takes_value(true)
.default_value("netspeed.ymgyt.io:5555"),
)
.arg(
Arg::with_name("duration")
.long("duration")
.alias("duration-seconds")
.help("Speed test duration seconds(max: 10)")
.takes_value(true)
.default_value("3")
.validator(|s| {
let n = s.parse::<u8>().map_err(|err| format!("{}", err))?;
if n > 10 {
Err("Max duration exceeded (max: 10)".to_owned())
} else {
Ok(())
}
})
.value_name("SECONDS"),
)
.subcommand(
App::new("server")
.about("Server mode")
.arg(
Arg::with_name("run")
.index(1)
.required(true)
.help("Running server"),
)
.arg(
Arg::with_name("address")
.long("addr")
.alias("address")
.short("a")
.help("Listening address")
.takes_value(true)
.default_value("0.0.0.0:5555"),
)
.arg(
Arg::with_name("max-threads")
.long("max-threads")
.alias("max-workers")
.help("Max concurrent threads/workers")
.takes_value(true)
.default_value("100")
.value_name("NUMBER"),
),
)
.get_matches_from(args)
}
}