summaryrefslogtreecommitdiffhomepage
path: root/mullvad-cli/src
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2020-05-08 11:08:10 +0200
committerDavid Lönnhager <david.l@mullvad.net>2020-05-08 17:22:57 +0200
commit4ebb74586ae0e53cdbe997aa950129c7d2e2c639 (patch)
tree9c876de4af476579863beaf5e7b7a7e3971c9126 /mullvad-cli/src
parentdc188c31e9a8851a6c2cc9fea0921919f220edc3 (diff)
downloadmullvadvpn-4ebb74586ae0e53cdbe997aa950129c7d2e2c639.tar.xz
mullvadvpn-4ebb74586ae0e53cdbe997aa950129c7d2e2c639.zip
Make locations case-insensitive in the CLI
Diffstat (limited to 'mullvad-cli/src')
-rw-r--r--mullvad-cli/src/location.rs24
1 files changed, 10 insertions, 14 deletions
diff --git a/mullvad-cli/src/location.rs b/mullvad-cli/src/location.rs
index 75fe237c81..20853893b8 100644
--- a/mullvad-cli/src/location.rs
+++ b/mullvad-cli/src/location.rs
@@ -23,27 +23,23 @@ pub fn get_subcommand() -> clap::App<'static, 'static> {
}
pub fn get_constraint(matches: &clap::ArgMatches<'_>) -> Constraint<LocationConstraint> {
- let country = matches.value_of("country").unwrap();
- let city = matches.value_of("city");
- let hostname = matches.value_of("hostname");
+ let country_original = matches.value_of("country").unwrap();
+ let country = country_original.to_lowercase();
+ let city = matches.value_of("city").map(str::to_lowercase);
+ let hostname = matches.value_of("hostname").map(str::to_lowercase);
- match (country, city, hostname) {
+ match (country_original, city, hostname) {
("any", None, None) => Constraint::Any,
("any", ..) => clap::Error::with_description(
"City can't be given when selecting 'any' country",
clap::ErrorKind::InvalidValue,
)
.exit(),
- (country, None, None) => Constraint::Only(LocationConstraint::Country(country.to_owned())),
- (country, Some(city), None) => Constraint::Only(LocationConstraint::City(
- country.to_owned(),
- city.to_owned(),
- )),
- (country, Some(city), Some(hostname)) => Constraint::Only(LocationConstraint::Hostname(
- country.to_owned(),
- city.to_owned(),
- hostname.to_owned(),
- )),
+ (_, None, None) => Constraint::Only(LocationConstraint::Country(country)),
+ (_, Some(city), None) => Constraint::Only(LocationConstraint::City(country, city)),
+ (_, Some(city), Some(hostname)) => {
+ Constraint::Only(LocationConstraint::Hostname(country, city, hostname))
+ }
(..) => clap::Error::with_description(
"Invalid country, city and hostname combination given",
clap::ErrorKind::InvalidValue,