chore: refactor clap multiple_occurrences and multiple_values (#130)

This commit is contained in:
sigoden
2022-08-27 10:30:08 +08:00
committed by GitHub
parent 31c832a742
commit bde06fef94
3 changed files with 105 additions and 76 deletions

View File

@@ -1,4 +1,4 @@
use clap::{value_parser, AppSettings, Arg, ArgMatches, Command};
use clap::{value_parser, AppSettings, Arg, ArgAction, ArgMatches, Command};
use clap_complete::{generate, Generator, Shell};
#[cfg(feature = "tls")]
use rustls::{Certificate, PrivateKey};
@@ -30,7 +30,8 @@ pub fn build_cli() -> Command<'static> {
.long("bind")
.help("Specify bind address")
.multiple_values(true)
.multiple_occurrences(true)
.value_delimiter(',')
.action(ArgAction::Append)
.value_name("addr"),
)
.arg(
@@ -56,7 +57,10 @@ pub fn build_cli() -> Command<'static> {
.arg(
Arg::new("hidden")
.long("hidden")
.help("Hide paths from directory listings, separated by `,`")
.help("Hide paths from directory listings")
.multiple_values(true)
.value_delimiter(',')
.action(ArgAction::Append)
.value_name("value"),
)
.arg(
@@ -64,8 +68,9 @@ pub fn build_cli() -> Command<'static> {
.short('a')
.long("auth")
.help("Add auth for path")
.action(ArgAction::Append)
.multiple_values(true)
.multiple_occurrences(true)
.value_delimiter(',')
.value_name("rule"),
)
.arg(
@@ -207,8 +212,8 @@ impl Args {
format!("/{}/", &encode_uri(&path_prefix))
};
let hidden: Vec<String> = matches
.value_of("hidden")
.map(|v| v.split(',').map(|x| x.to_string()).collect())
.values_of("hidden")
.map(|v| v.map(|v| v.to_string()).collect())
.unwrap_or_default();
let enable_cors = matches.is_present("enable-cors");
let auth: Vec<&str> = matches