diff options
| author | Linus Färnstrand <linus@mullvad.net> | 2017-07-07 16:46:30 +0200 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2017-07-10 10:00:32 +0200 |
| commit | caddbcfdf579d7a91a4e4d8f73791f88ff81c9f6 (patch) | |
| tree | cda3f94de8a75fabc7eebb059836f0fcd24480c4 /mullvad_cli/src/cmds | |
| parent | ef588b3ef2c0966d4e521058e5b8fadf11bab9f4 (diff) | |
| download | mullvadvpn-caddbcfdf579d7a91a4e4d8f73791f88ff81c9f6.tar.xz mullvadvpn-caddbcfdf579d7a91a4e4d8f73791f88ff81c9f6.zip | |
Add status support in CLI
Diffstat (limited to 'mullvad_cli/src/cmds')
| -rw-r--r-- | mullvad_cli/src/cmds/account.rs | 13 | ||||
| -rw-r--r-- | mullvad_cli/src/cmds/mod.rs | 10 | ||||
| -rw-r--r-- | mullvad_cli/src/cmds/status.rs | 29 |
3 files changed, 43 insertions, 9 deletions
diff --git a/mullvad_cli/src/cmds/account.rs b/mullvad_cli/src/cmds/account.rs index c6300e0eb3..fcfe9f9901 100644 --- a/mullvad_cli/src/cmds/account.rs +++ b/mullvad_cli/src/cmds/account.rs @@ -2,7 +2,6 @@ use Command; use Result; use clap; use rpc; -use serde_json; pub struct Account; @@ -39,17 +38,17 @@ impl Command for Account { impl Account { fn set(&self, token: &str) -> Result<()> { rpc::call("set_account", &[token]).map( - |_| { - println!("Mullvad account {} set", token); + |_: Option<()>| { + println!("Mullvad account \"{}\" set", token); }, ) } fn get(&self) -> Result<()> { - match rpc::call("get_account", &[] as &[u8; 0])? { - serde_json::Value::String(token) => println!("Mullvad account: {:?}", token), - serde_json::Value::Null => println!("No account configured"), - _ => bail!("Unable to fetch account token"), + let token: Option<String> = rpc::call("get_account", &[] as &[u8; 0])?; + match token { + Some(token) => println!("Mullvad account: {:?}", token), + None => println!("No account configured"), } Ok(()) } diff --git a/mullvad_cli/src/cmds/mod.rs b/mullvad_cli/src/cmds/mod.rs index 3f881bcfb8..aca46b9aa3 100644 --- a/mullvad_cli/src/cmds/mod.rs +++ b/mullvad_cli/src/cmds/mod.rs @@ -2,11 +2,17 @@ use Command; use std::collections::HashMap; mod account; -pub use self::account::*; +pub use self::account::Account; + +mod status; +pub use self::status::Status; /// Returns a map of all available subcommands with their name as key. pub fn get_commands() -> HashMap<&'static str, Box<Command>> { - let commands = vec![Box::new(Account) as Box<Command>]; + let commands = vec![ + Box::new(Account) as Box<Command>, + Box::new(Status) as Box<Command>, + ]; let mut map = HashMap::new(); for cmd in commands { if let Some(_) = map.insert(cmd.name(), cmd) { diff --git a/mullvad_cli/src/cmds/status.rs b/mullvad_cli/src/cmds/status.rs new file mode 100644 index 0000000000..e02773285f --- /dev/null +++ b/mullvad_cli/src/cmds/status.rs @@ -0,0 +1,29 @@ +use Command; +use Result; +use clap; + +use mullvad_types::states::{DaemonState, SecurityState, TargetState}; +use rpc; + +pub struct Status; + +impl Command for Status { + fn name(&self) -> &'static str { + "status" + } + + fn clap_subcommand(&self) -> clap::App<'static, 'static> { + clap::SubCommand::with_name(self.name()).about("View the state of the VPN tunnel") + } + + fn run(&self, _matches: &clap::ArgMatches) -> Result<()> { + let state: DaemonState = rpc::call("get_state", &[] as &[u8; 0])?; + match (state.state, state.target_state) { + (SecurityState::Unsecured, TargetState::Unsecured) => println!("Disconnected"), + (SecurityState::Unsecured, TargetState::Secured) => println!("Connecting..."), + (SecurityState::Secured, TargetState::Unsecured) => println!("Disconnecting..."), + (SecurityState::Secured, TargetState::Secured) => println!("Connected"), + } + Ok(()) + } +} |
