diff options
Diffstat (limited to 'mullvad-cli/src')
| -rw-r--r-- | mullvad-cli/src/cmds/account.rs | 28 | ||||
| -rw-r--r-- | mullvad-cli/src/cmds/custom_relay.rs | 56 | ||||
| -rw-r--r-- | mullvad-cli/src/main.rs | 8 | ||||
| -rw-r--r-- | mullvad-cli/src/rpc.rs | 17 |
4 files changed, 61 insertions, 48 deletions
diff --git a/mullvad-cli/src/cmds/account.rs b/mullvad-cli/src/cmds/account.rs index f7cb106fc3..0dda601fc9 100644 --- a/mullvad-cli/src/cmds/account.rs +++ b/mullvad-cli/src/cmds/account.rs @@ -15,13 +15,19 @@ impl Command for Account { clap::SubCommand::with_name(self.name()) .about("Control and display information about your Mullvad account") .setting(clap::AppSettings::SubcommandRequired) - .subcommand(clap::SubCommand::with_name("set") - .about("Change account") - .arg(clap::Arg::with_name("token") - .help("The Mullvad account token to configure the client with") - .required(true))) - .subcommand(clap::SubCommand::with_name("get") - .about("Display information about the currently configured account")) + .subcommand( + clap::SubCommand::with_name("set") + .about("Change account") + .arg( + clap::Arg::with_name("token") + .help("The Mullvad account token to configure the client with") + .required(true), + ), + ) + .subcommand( + clap::SubCommand::with_name("get") + .about("Display information about the currently configured account"), + ) } fn run(&self, matches: &clap::ArgMatches) -> Result<()> { @@ -38,11 +44,9 @@ impl Command for Account { impl Account { fn set(&self, token: &str) -> Result<()> { - rpc::call("set_account", &[token]).map( - |_: Option<()>| { - println!("Mullvad account \"{}\" set", token); - }, - ) + rpc::call("set_account", &[token]).map(|_: Option<()>| { + println!("Mullvad account \"{}\" set", token); + }) } fn get(&self) -> Result<()> { diff --git a/mullvad-cli/src/cmds/custom_relay.rs b/mullvad-cli/src/cmds/custom_relay.rs index ab9a148fb3..d37169d52a 100644 --- a/mullvad-cli/src/cmds/custom_relay.rs +++ b/mullvad-cli/src/cmds/custom_relay.rs @@ -17,21 +17,33 @@ impl Command for CustomRelay { clap::SubCommand::with_name(self.name()) .about("Set or remove custom relay") .setting(clap::AppSettings::SubcommandRequired) - .subcommand(clap::SubCommand::with_name("set") - .about("Set a custom relay") - .arg(clap::Arg::with_name("host") - .help("The host name or IP of the relay") - .required(true)) - .arg(clap::Arg::with_name("port") - .help("The port of the relay") - .required(true)) - .arg(clap::Arg::with_name("protocol") - .help("The transport protocol. UDP is recommended as it usually results in - higher throughput than TCP") - .possible_values(&["udp", "tcp"]) - .default_value("udp"))) - .subcommand(clap::SubCommand::with_name("remove") - .about("Remove the custom relay and use the default relays instead")) + .subcommand( + clap::SubCommand::with_name("set") + .about("Set a custom relay") + .arg( + clap::Arg::with_name("host") + .help("The host name or IP of the relay") + .required(true), + ) + .arg( + clap::Arg::with_name("port") + .help("The port of the relay") + .required(true), + ) + .arg( + clap::Arg::with_name("protocol") + .help( + "The transport protocol. UDP is recommended as it usually results in + higher throughput than TCP", + ) + .possible_values(&["udp", "tcp"]) + .default_value("udp"), + ), + ) + .subcommand( + clap::SubCommand::with_name("remove") + .about("Remove the custom relay and use the default relays instead"), + ) } fn run(&self, matches: &clap::ArgMatches) -> Result<()> { @@ -57,18 +69,12 @@ impl CustomRelay { protocol, }; - rpc::call( - "set_custom_relay", - &[relay_endpoint], - ) - .map(|_: Option<()>| println!("Custom relay set")) + rpc::call("set_custom_relay", &[relay_endpoint]) + .map(|_: Option<()>| println!("Custom relay set")) } fn remove(&self) -> Result<()> { - rpc::call( - "remove_custom_relay", - &[] as &[u8; 0], - ) - .map(|_: Option<()>| println!("Custom relay removed")) + rpc::call("remove_custom_relay", &[] as &[u8; 0]) + .map(|_: Option<()>| println!("Custom relay removed")) } } diff --git a/mullvad-cli/src/main.rs b/mullvad-cli/src/main.rs index 8543f7eecb..edcfbe3553 100644 --- a/mullvad-cli/src/main.rs +++ b/mullvad-cli/src/main.rs @@ -9,20 +9,20 @@ // `error_chain!` can recurse deeply #![recursion_limit = "1024"] -extern crate mullvad_types; -extern crate talpid_types; -extern crate talpid_ipc; #[macro_use] extern crate clap; +extern crate env_logger; #[macro_use] extern crate error_chain; #[macro_use] extern crate lazy_static; #[macro_use] extern crate log; -extern crate env_logger; +extern crate mullvad_types; extern crate serde; extern crate serde_json; +extern crate talpid_ipc; +extern crate talpid_types; mod rpc; mod cmds; diff --git a/mullvad-cli/src/rpc.rs b/mullvad-cli/src/rpc.rs index d6569878cd..bd1d6e571b 100644 --- a/mullvad-cli/src/rpc.rs +++ b/mullvad-cli/src/rpc.rs @@ -6,21 +6,24 @@ use std::path::{Path, PathBuf}; use talpid_ipc::WsIpcClient; pub fn call<T, O>(method: &str, args: &T) -> Result<O> - where T: serde::Serialize, - O: for<'de> serde::Deserialize<'de> +where + T: serde::Serialize, + O: for<'de> serde::Deserialize<'de>, { call_internal(method, args).chain_err(|| "Unable to call backend over RPC") } pub fn call_internal<T, O>(method: &str, args: &T) -> Result<O> - where T: serde::Serialize, - O: for<'de> serde::Deserialize<'de> +where + T: serde::Serialize, + O: for<'de> serde::Deserialize<'de>, { let address = read_rpc_address().chain_err(|| "Unable to read RPC address")?; info!("Using RPC address {}", address); - let mut rpc_client = WsIpcClient::new(address) - .chain_err(|| "Unable to create RPC client")?; - rpc_client.call(method, args).chain_err(|| format!("Unable to call RPC method {}", method)) + let mut rpc_client = WsIpcClient::new(address).chain_err(|| "Unable to create RPC client")?; + rpc_client + .call(method, args) + .chain_err(|| format!("Unable to call RPC method {}", method)) } |
