Skip to content

Commit

Permalink
Update Rust crate clap to 3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
zdz committed Jun 14, 2022
1 parent 67d417c commit bc37287
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 21 deletions.
2 changes: 1 addition & 1 deletion client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ repository = "https://github.com/zdz/ServerStatus-Rust"
anyhow = "1"
bytes = {version = "1", features = ["serde"]}
chrono = "0.4"
clap = {version = "3.1", features = ["derive"]}
clap = {version = "3.2", features = ["derive"]}
hyper = {version = "0.14", features = ["full"]}
lazy_static = "1.4"
log = "0.4"
Expand Down
60 changes: 45 additions & 15 deletions client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,43 +39,73 @@ pub static G_CONFIG: Lazy<Mutex<ClientConfig>> = Lazy::new(|| Mutex::new(ClientC
#[derive(Parser, Debug, Clone)]
#[clap(author, version = env!("APP_VERSION"), about, long_about = None)]
pub struct Args {
#[clap(short, long, default_value = "http://127.0.0.1:8080/report")]
#[clap(
short,
long,
value_parser,
default_value = "http://127.0.0.1:8080/report"
)]
addr: String,
#[clap(short, long, default_value = "h1", help = "username")]
#[clap(short, long, value_parser, default_value = "h1", help = "username")]
user: String,
#[clap(short, long, default_value = "p1", help = "password")]
#[clap(short, long, value_parser, default_value = "p1", help = "password")]
pass: String,
#[clap(short = 'n', long, help = "enable vnstat, default:false")]
#[clap(short = 'n', long, value_parser, help = "enable vnstat, default:false")]
vnstat: bool,
#[clap(long = "disable-tupd", help = "disable t/u/p/d, default:false")]
#[clap(
long = "disable-tupd",
value_parser,
help = "disable t/u/p/d, default:false"
)]
disable_tupd: bool,
#[clap(long = "disable-ping", help = "disable ping, default:false")]
#[clap(
long = "disable-ping",
value_parser,
help = "disable ping, default:false"
)]
disable_ping: bool,
#[clap(
long = "disable-extra",
value_parser,
help = "disable extra info report, default:false"
)]
disable_extra: bool,
#[clap(long = "ct", default_value = CT, help = "China Telecom probe addr")]
#[clap(long = "ct", value_parser, default_value = CT, help = "China Telecom probe addr")]
ct_addr: String,
#[clap(long = "cm", default_value = CM, help = "China Mobile probe addr")]
#[clap(long = "cm", value_parser, default_value = CM, help = "China Mobile probe addr")]
cm_addr: String,
#[clap(long = "cu", default_value = CU, help = "China Unicom probe addr")]
#[clap(long = "cu", value_parser, default_value = CU, help = "China Unicom probe addr")]
cu_addr: String,
#[clap(long = "ip-info", help = "show ip info, default:false")]
#[clap(long = "ip-info", value_parser, help = "show ip info, default:false")]
ip_info: bool,
#[clap(long = "json", help = "use json protocol, default:false")]
#[clap(long = "json", value_parser, help = "use json protocol, default:false")]
json: bool,
#[clap(short = '6', long = "ipv6", help = "ipv6 only, default:false")]
#[clap(
short = '6',
value_parser,
long = "ipv6",
help = "ipv6 only, default:false"
)]
ipv6: bool,
// #[clap(long = "debug", help = "debug mode, default:false")]
// debug: bool,
// for group
#[clap(short, long, default_value = "", help = "group id")]
#[clap(short, long, value_parser, default_value = "", help = "group id")]
gid: String,
#[clap(long = "alias", default_value = "unknown", help = "alias for host")]
#[clap(
long = "alias",
value_parser,
default_value = "unknown",
help = "alias for host"
)]
alias: String,
#[clap(short, long, default_value = "0", help = "weight for rank")]
#[clap(
short,
long,
value_parser,
default_value = "0",
help = "weight for rank"
)]
weight: u64,
}

Expand Down
2 changes: 1 addition & 1 deletion server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ repository = "https://github.com/zdz/ServerStatus-Rust"
anyhow = "1"
bytes = {version = "1", features = ["serde"]}
chrono = "0.4"
clap = {version = "3.1", features = ["derive"]}
clap = {version = "3.2", features = ["derive"]}
futures = "0.3"
futures-util = {version = "0.3", default-features = false}
http-auth-basic = "0.3"
Expand Down
16 changes: 12 additions & 4 deletions server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,21 @@ struct Asset;
#[derive(Parser, Debug)]
#[clap(author, version = env!("APP_VERSION"), about, long_about = None)]
struct Args {
#[clap(short, long, default_value = "config.toml")]
#[clap(short, long, value_parser, default_value = "config.toml")]
config: String,
#[clap(short = 't', long, help = "config test, default:false")]
#[clap(short = 't', long, value_parser, help = "config test, default:false")]
config_test: bool,
#[clap(long = "notify-test", help = "notify test, default:false")]
#[clap(
long = "notify-test",
value_parser,
help = "notify test, default:false"
)]
notify_test: bool,
#[clap(long = "cloud", help = "cloud mode, load cfg from env var: SRV_CONF")]
#[clap(
long = "cloud",
value_parser,
help = "cloud mode, load cfg from env var: SRV_CONF"
)]
cloud: bool,
}

Expand Down

0 comments on commit bc37287

Please sign in to comment.