summaryrefslogtreecommitdiffhomepage
path: root/mullvad-cli/src/location.rs
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2022-02-11 13:56:23 +0100
committerDavid Lönnhager <david.l@mullvad.net>2022-02-14 17:50:37 +0100
commitbc9edac3fe447240798ffa3d56aa42c211453a92 (patch)
tree32680ab33cdf6c237ac8f5fc93cd88b16098ae19 /mullvad-cli/src/location.rs
parent990dcd256d2c1606d4b1c135a2e979e9cefb4ab7 (diff)
downloadmullvadvpn-bc9edac3fe447240798ffa3d56aa42c211453a92.tar.xz
mullvadvpn-bc9edac3fe447240798ffa3d56aa42c211453a92.zip
Upgrade clap to 3.0
Diffstat (limited to 'mullvad-cli/src/location.rs')
-rw-r--r--mullvad-cli/src/location.rs32
1 files changed, 14 insertions, 18 deletions
diff --git a/mullvad-cli/src/location.rs b/mullvad-cli/src/location.rs
index e4719f7d37..2fff68998c 100644
--- a/mullvad-cli/src/location.rs
+++ b/mullvad-cli/src/location.rs
@@ -1,28 +1,24 @@
use mullvad_management_interface::types::RelayLocation;
-pub fn get_subcommand() -> clap::App<'static, 'static> {
- clap::SubCommand::with_name("location")
+pub fn get_subcommand() -> clap::App<'static> {
+ clap::App::new("location")
.arg(
- clap::Arg::with_name("country")
+ clap::Arg::new("country")
.help("The two letter country code, or 'any' for no preference.")
.required(true)
.index(1)
.validator(country_code_validator),
)
.arg(
- clap::Arg::with_name("city")
+ clap::Arg::new("city")
.help("The three letter city code")
.index(2)
.validator(city_code_validator),
)
- .arg(
- clap::Arg::with_name("hostname")
- .help("The hostname")
- .index(3),
- )
+ .arg(clap::Arg::new("hostname").help("The hostname").index(3))
}
-pub fn get_constraint_from_args(matches: &clap::ArgMatches<'_>) -> RelayLocation {
+pub fn get_constraint_from_args(matches: &clap::ArgMatches) -> RelayLocation {
let country = matches.value_of("country").unwrap();
let city = matches.value_of("city");
let hostname = matches.value_of("hostname");
@@ -41,9 +37,9 @@ pub fn get_constraint<T: AsRef<str>>(
match (country_original, city, hostname) {
("any", None, None) => RelayLocation::default(),
- ("any", ..) => clap::Error::with_description(
- "City can't be given when selecting 'any' country",
+ ("any", ..) => clap::Error::raw(
clap::ErrorKind::InvalidValue,
+ "City can't be given when selecting 'any' country",
)
.exit(),
(_, None, None) => RelayLocation {
@@ -60,24 +56,24 @@ pub fn get_constraint<T: AsRef<str>>(
city,
hostname,
},
- (..) => clap::Error::with_description(
- "Invalid country, city and hostname combination given",
+ (..) => clap::Error::raw(
clap::ErrorKind::InvalidValue,
+ "Invalid country, city and hostname combination given",
)
.exit(),
}
}
-pub fn country_code_validator<T: AsRef<str>>(code: T) -> std::result::Result<(), String> {
- if code.as_ref().len() == 2 || code.as_ref() == "any" {
+pub fn country_code_validator(code: &str) -> std::result::Result<(), String> {
+ if code.len() == 2 || code == "any" {
Ok(())
} else {
Err(String::from("Country codes must be two letters, or 'any'."))
}
}
-pub fn city_code_validator<T: AsRef<str>>(code: T) -> std::result::Result<(), String> {
- if code.as_ref().len() == 3 {
+pub fn city_code_validator(code: &str) -> std::result::Result<(), String> {
+ if code.len() == 3 {
Ok(())
} else {
Err(String::from("City codes must be three letters"))