summaryrefslogtreecommitdiffhomepage
path: root/mullvad_cli/src
diff options
context:
space:
mode:
authorLinus Färnstrand <linus@mullvad.net>2017-07-07 16:46:50 +0200
committerLinus Färnstrand <linus@mullvad.net>2017-07-10 10:00:32 +0200
commit0e4f7c3665c8704a29a31cad0875a93d2b1cb20f (patch)
treecc220f7b9dd6b0de8322ce36fecf7355b53712cc /mullvad_cli/src
parentcaddbcfdf579d7a91a4e4d8f73791f88ff81c9f6 (diff)
downloadmullvadvpn-0e4f7c3665c8704a29a31cad0875a93d2b1cb20f.tar.xz
mullvadvpn-0e4f7c3665c8704a29a31cad0875a93d2b1cb20f.zip
Add connect and disconnect support to CLI
Diffstat (limited to 'mullvad_cli/src')
-rw-r--r--mullvad_cli/src/cmds/connect.rs22
-rw-r--r--mullvad_cli/src/cmds/disconnect.rs22
-rw-r--r--mullvad_cli/src/cmds/mod.rs8
3 files changed, 52 insertions, 0 deletions
diff --git a/mullvad_cli/src/cmds/connect.rs b/mullvad_cli/src/cmds/connect.rs
new file mode 100644
index 0000000000..4847a0805a
--- /dev/null
+++ b/mullvad_cli/src/cmds/connect.rs
@@ -0,0 +1,22 @@
+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
new file mode 100644
index 0000000000..543aa9d0cc
--- /dev/null
+++ b/mullvad_cli/src/cmds/disconnect.rs
@@ -0,0 +1,22 @@
+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
index aca46b9aa3..e751c91734 100644
--- a/mullvad_cli/src/cmds/mod.rs
+++ b/mullvad_cli/src/cmds/mod.rs
@@ -7,11 +7,19 @@ 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::new(Account) as Box<Command>,
Box::new(Status) as Box<Command>,
+ Box::new(Connect) as Box<Command>,
+ Box::new(Disconnect) as Box<Command>,
];
let mut map = HashMap::new();
for cmd in commands {