summaryrefslogtreecommitdiffhomepage
path: root/mullvad-cli
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2021-02-10 11:23:50 +0100
committerDavid Lönnhager <david.l@mullvad.net>2021-02-10 11:23:50 +0100
commitad0349274f059d5a1fafe0e95241e5e60875fd80 (patch)
tree382fd385d9c74806a5c1f9f026f6886df95755ce /mullvad-cli
parent7b68e34745ee18081223c706f48b5bc2ed2fc9e9 (diff)
parent8d59a7b38f999c6e900bf2263af05bce0c4e66e4 (diff)
downloadmullvadvpn-ad0349274f059d5a1fafe0e95241e5e60875fd80.tar.xz
mullvadvpn-ad0349274f059d5a1fafe0e95241e5e60875fd80.zip
Merge branch 'add-multiple-providers'
Diffstat (limited to 'mullvad-cli')
-rw-r--r--mullvad-cli/src/cmds/bridge.rs31
-rw-r--r--mullvad-cli/src/cmds/relay.rs34
-rw-r--r--mullvad-cli/src/location.rs6
3 files changed, 37 insertions, 34 deletions
diff --git a/mullvad-cli/src/cmds/bridge.rs b/mullvad-cli/src/cmds/bridge.rs
index 9a674069a8..b6692d0198 100644
--- a/mullvad-cli/src/cmds/bridge.rs
+++ b/mullvad-cli/src/cmds/bridge.rs
@@ -1,5 +1,5 @@
use crate::{location, new_rpc_client, Command, Error, Result};
-use clap::value_t;
+use clap::{value_t, values_t};
use mullvad_management_interface::types::{
bridge_settings::{Type as BridgeSettingsType, *},
@@ -48,12 +48,13 @@ fn create_bridge_set_subcommand() -> clap::App<'static, 'static> {
.subcommand(
clap::SubCommand::with_name("provider")
.about(
- "Set a hosting provider to select bridge relays from. The 'list' \
+ "Set hosting provider(s) to select bridge relays from. The 'list' \
command shows the available relays and their providers.",
)
.arg(
clap::Arg::with_name("provider")
- .help("The hosting provider to use, or 'any' for no preference.")
+ .help("The hosting provider(s) to use, or 'any' for no preference.")
+ .multiple(true)
.required(true),
),
)
@@ -192,7 +193,7 @@ impl Bridge {
println!(
"Bridge constraints - {}, {}",
location::format_location(constraints.location.as_ref()),
- location::format_provider(constraints.provider.as_ref())
+ location::format_providers(&constraints.providers)
);
}
};
@@ -204,20 +205,20 @@ impl Bridge {
}
async fn handle_set_bridge_provider(matches: &clap::ArgMatches<'_>) -> Result<()> {
- let new_provider =
- value_t!(matches.value_of("provider"), String).unwrap_or_else(|e| e.exit());
- let new_provider = if new_provider == "any" {
- "".to_string()
+ let providers =
+ values_t!(matches.values_of("provider"), String).unwrap_or_else(|e| e.exit());
+ let providers = if providers.iter().next().map(String::as_str) == Some("any") {
+ vec![]
} else {
- new_provider
+ providers
};
- Self::update_bridge_settings(None, Some(new_provider)).await
+ Self::update_bridge_settings(None, Some(providers)).await
}
async fn update_bridge_settings(
location: Option<RelayLocation>,
- provider: Option<String>,
+ providers: Option<Vec<String>>,
) -> Result<()> {
let mut rpc = new_rpc_client().await?;
let settings = rpc.get_settings(()).await?.into_inner();
@@ -228,18 +229,18 @@ impl Bridge {
if let Some(new_location) = location {
constraints.location = Some(new_location);
}
- if let Some(new_provider) = provider {
- constraints.provider = new_provider;
+ if let Some(new_providers) = providers {
+ constraints.providers = new_providers;
}
constraints
}
_ => {
let location = location.unwrap_or_default();
- let provider = provider.unwrap_or_default();
+ let providers = providers.unwrap_or_default();
BridgeConstraints {
location: Some(location),
- provider,
+ providers,
}
}
};
diff --git a/mullvad-cli/src/cmds/relay.rs b/mullvad-cli/src/cmds/relay.rs
index e8783e04f3..4ad950fe7a 100644
--- a/mullvad-cli/src/cmds/relay.rs
+++ b/mullvad-cli/src/cmds/relay.rs
@@ -128,11 +128,12 @@ impl Command for Relay {
)
.subcommand(
clap::SubCommand::with_name("provider")
- .about("Set a hosting provider to select relays from. The 'list' \
+ .about("Set hosting provider(s) to select relays from. The 'list' \
command shows the available relays and their providers.")
.arg(
clap::Arg::with_name("provider")
- .help("The hosting provider to use, or 'any' for no preference.")
+ .help("The hosting provider(s) to use, or 'any' for no preference.")
+ .multiple(true)
.required(true)
)
)
@@ -207,8 +208,8 @@ impl Relay {
self.set_location(location_matches).await
} else if let Some(relay_matches) = matches.subcommand_matches("hostname") {
self.set_hostname(relay_matches).await
- } else if let Some(provider_matches) = matches.subcommand_matches("provider") {
- self.set_provider(provider_matches).await
+ } else if let Some(providers_matches) = matches.subcommand_matches("provider") {
+ self.set_providers(providers_matches).await
} else if let Some(tunnel_matches) = matches.subcommand_matches("tunnel") {
self.set_tunnel(tunnel_matches).await
} else if let Some(tunnel_matches) = matches.subcommand_matches("tunnel-protocol") {
@@ -440,19 +441,20 @@ impl Relay {
.await
}
- async fn set_provider(&self, matches: &clap::ArgMatches<'_>) -> Result<()> {
- let provider = value_t!(matches.value_of("provider"), String).unwrap_or_else(|e| e.exit());
+ async fn set_providers(&self, matches: &clap::ArgMatches<'_>) -> Result<()> {
+ let providers =
+ values_t!(matches.values_of("provider"), String).unwrap_or_else(|e| e.exit());
+
+ let providers = if providers.iter().next().map(String::as_str) == Some("any") {
+ vec![]
+ } else {
+ providers
+ };
self.update_constraints(RelaySettingsUpdate {
r#type: Some(relay_settings_update::Type::Normal(
NormalRelaySettingsUpdate {
- provider: Some(ProviderUpdate {
- provider: if provider == "any" {
- "".to_string()
- } else {
- provider
- },
- }),
+ providers: Some(ProviderUpdate { providers }),
..Default::default()
},
)),
@@ -545,7 +547,7 @@ impl Relay {
Self::format_openvpn_constraints(settings.openvpn_constraints.as_ref()),
Self::format_wireguard_constraints(settings.wireguard_constraints.as_ref()),
location::format_location(settings.location.as_ref()),
- location::format_provider(settings.provider.as_ref())
+ location::format_providers(&settings.providers)
);
}
Some(constraint) => match TunnelType::from_i32(constraint.tunnel_type).unwrap() {
@@ -556,7 +558,7 @@ impl Relay {
settings.wireguard_constraints.as_ref()
),
location::format_location(settings.location.as_ref()),
- location::format_provider(settings.provider.as_ref())
+ location::format_providers(&settings.providers)
);
}
TunnelType::Openvpn => {
@@ -564,7 +566,7 @@ impl Relay {
"OpenVPN over {} in {} using {}",
Self::format_openvpn_constraints(settings.openvpn_constraints.as_ref()),
location::format_location(settings.location.as_ref()),
- location::format_provider(settings.provider.as_ref())
+ location::format_providers(&settings.providers)
);
}
},
diff --git a/mullvad-cli/src/location.rs b/mullvad-cli/src/location.rs
index bc4c9bc630..09f39720ba 100644
--- a/mullvad-cli/src/location.rs
+++ b/mullvad-cli/src/location.rs
@@ -73,9 +73,9 @@ pub fn format_location(location: Option<&RelayLocation>) -> String {
"any location".to_string()
}
-pub fn format_provider(provider: &str) -> String {
- if !provider.is_empty() {
- format!("provider {}", provider)
+pub fn format_providers(providers: &Vec<String>) -> String {
+ if !providers.is_empty() {
+ format!("provider(s) {}", providers.join(", "))
} else {
"any provider".to_string()
}