diff options
| author | Linus Färnstrand <linus@mullvad.net> | 2017-07-17 10:36:52 +0200 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2017-07-17 10:48:09 +0200 |
| commit | f07f1a0262c908ff83490850b67a167f963efc2d (patch) | |
| tree | 5a5209baefc0b10ba528f254e7ce2456c23f6ac9 /mullvad_cli/src/cmds | |
| parent | 6a4202fc8c55752f0fef86c04b628a3f9ada5279 (diff) | |
| download | mullvadvpn-f07f1a0262c908ff83490850b67a167f963efc2d.tar.xz mullvadvpn-f07f1a0262c908ff83490850b67a167f963efc2d.zip | |
Rename all crates from snake_case to kebab-case
Diffstat (limited to 'mullvad_cli/src/cmds')
| -rw-r--r-- | mullvad_cli/src/cmds/account.rs | 55 | ||||
| -rw-r--r-- | mullvad_cli/src/cmds/connect.rs | 22 | ||||
| -rw-r--r-- | mullvad_cli/src/cmds/disconnect.rs | 22 | ||||
| -rw-r--r-- | mullvad_cli/src/cmds/mod.rs | 31 | ||||
| -rw-r--r-- | mullvad_cli/src/cmds/status.rs | 29 |
5 files changed, 0 insertions, 159 deletions
diff --git a/mullvad_cli/src/cmds/account.rs b/mullvad_cli/src/cmds/account.rs deleted file mode 100644 index fcfe9f9901..0000000000 --- a/mullvad_cli/src/cmds/account.rs +++ /dev/null @@ -1,55 +0,0 @@ -use Command; -use Result; -use clap; -use rpc; - -pub struct Account; - -impl Command for Account { - fn name(&self) -> &'static str { - "account" - } - - fn clap_subcommand(&self) -> clap::App<'static, 'static> { - 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")) - } - - fn run(&self, matches: &clap::ArgMatches) -> Result<()> { - if let Some(set_matches) = matches.subcommand_matches("set") { - let token = value_t_or_exit!(set_matches.value_of("token"), String); - self.set(&token) - } else if let Some(_matches) = matches.subcommand_matches("get") { - self.get() - } else { - unreachable!("No account command given"); - } - } -} - -impl Account { - fn set(&self, token: &str) -> Result<()> { - rpc::call("set_account", &[token]).map( - |_: Option<()>| { - println!("Mullvad account \"{}\" set", token); - }, - ) - } - - fn get(&self) -> Result<()> { - 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/connect.rs b/mullvad_cli/src/cmds/connect.rs deleted file mode 100644 index 4847a0805a..0000000000 --- a/mullvad_cli/src/cmds/connect.rs +++ /dev/null @@ -1,22 +0,0 @@ -use Command; -use Result; -use clap; -use rpc; - -pub struct Connect; - -impl Command for Connect { - fn name(&self) -> &'static str { - "connect" - } - - fn clap_subcommand(&self) -> clap::App<'static, 'static> { - clap::SubCommand::with_name(self.name()) - .about("Command the client to start establishing a VPN tunnel") - } - - fn run(&self, _matches: &clap::ArgMatches) -> Result<()> { - let _response: Option<()> = rpc::call("connect", &[] as &[u8; 0])?; - Ok(()) - } -} diff --git a/mullvad_cli/src/cmds/disconnect.rs b/mullvad_cli/src/cmds/disconnect.rs deleted file mode 100644 index 543aa9d0cc..0000000000 --- a/mullvad_cli/src/cmds/disconnect.rs +++ /dev/null @@ -1,22 +0,0 @@ -use Command; -use Result; -use clap; -use rpc; - -pub struct Disconnect; - -impl Command for Disconnect { - fn name(&self) -> &'static str { - "disconnect" - } - - fn clap_subcommand(&self) -> clap::App<'static, 'static> { - clap::SubCommand::with_name(self.name()) - .about("Command the client to disconnect the VPN tunnel") - } - - fn run(&self, _matches: &clap::ArgMatches) -> Result<()> { - let _response: Option<()> = rpc::call("disconnect", &[] as &[u8; 0])?; - Ok(()) - } -} diff --git a/mullvad_cli/src/cmds/mod.rs b/mullvad_cli/src/cmds/mod.rs deleted file mode 100644 index c621c0840a..0000000000 --- a/mullvad_cli/src/cmds/mod.rs +++ /dev/null @@ -1,31 +0,0 @@ -use Command; -use std::collections::HashMap; - -mod account; -pub use self::account::Account; - -mod status; -pub use self::status::Status; - -mod connect; -pub use self::connect::Connect; - -mod disconnect; -pub use self::disconnect::Disconnect; - -/// 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<Command>> = vec![ - Box::new(Account), - Box::new(Status), - Box::new(Connect), - Box::new(Disconnect), - ]; - let mut map = HashMap::new(); - for cmd in commands { - if let Some(_) = map.insert(cmd.name(), cmd) { - panic!("Multiple commands with the same name"); - } - } - map -} diff --git a/mullvad_cli/src/cmds/status.rs b/mullvad_cli/src/cmds/status.rs deleted file mode 100644 index e02773285f..0000000000 --- a/mullvad_cli/src/cmds/status.rs +++ /dev/null @@ -1,29 +0,0 @@ -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(()) - } -} |
