summaryrefslogtreecommitdiffhomepage
path: root/mullvad-cli/src/cmds/split_tunnel
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2022-02-11 13:56:23 +0100
committerDavid Lönnhager <david.l@mullvad.net>2022-02-14 17:50:37 +0100
commitbc9edac3fe447240798ffa3d56aa42c211453a92 (patch)
tree32680ab33cdf6c237ac8f5fc93cd88b16098ae19 /mullvad-cli/src/cmds/split_tunnel
parent990dcd256d2c1606d4b1c135a2e979e9cefb4ab7 (diff)
downloadmullvadvpn-bc9edac3fe447240798ffa3d56aa42c211453a92.tar.xz
mullvadvpn-bc9edac3fe447240798ffa3d56aa42c211453a92.zip
Upgrade clap to 3.0
Diffstat (limited to 'mullvad-cli/src/cmds/split_tunnel')
-rw-r--r--mullvad-cli/src/cmds/split_tunnel/linux.rs39
-rw-r--r--mullvad-cli/src/cmds/split_tunnel/windows.rs51
2 files changed, 40 insertions, 50 deletions
diff --git a/mullvad-cli/src/cmds/split_tunnel/linux.rs b/mullvad-cli/src/cmds/split_tunnel/linux.rs
index f9945d14d6..3480f27fb0 100644
--- a/mullvad-cli/src/cmds/split_tunnel/linux.rs
+++ b/mullvad-cli/src/cmds/split_tunnel/linux.rs
@@ -1,5 +1,4 @@
use crate::{new_rpc_client, Command, Result};
-use clap::value_t_or_exit;
pub struct SplitTunnel;
@@ -9,8 +8,8 @@ impl Command for SplitTunnel {
"split-tunnel"
}
- fn clap_subcommand(&self) -> clap::App<'static, 'static> {
- clap::SubCommand::with_name(self.name())
+ fn clap_subcommand(&self) -> clap::App<'static> {
+ clap::App::new(self.name())
.about(
"Manage split tunneling. To launch applications outside \
the tunnel, use the program 'mullvad-exclude'.",
@@ -19,55 +18,51 @@ impl Command for SplitTunnel {
.subcommand(create_pid_subcommand())
}
- async fn run(&self, matches: &clap::ArgMatches<'_>) -> Result<()> {
+ async fn run(&self, matches: &clap::ArgMatches) -> Result<()> {
match matches.subcommand() {
- ("pid", Some(pid_matches)) => Self::handle_pid_cmd(pid_matches).await,
+ Some(("pid", pid_matches)) => Self::handle_pid_cmd(pid_matches).await,
_ => unreachable!("unhandled comand"),
}
}
}
-fn create_pid_subcommand() -> clap::App<'static, 'static> {
- clap::SubCommand::with_name("pid")
+fn create_pid_subcommand() -> clap::App<'static> {
+ clap::App::new("pid")
.about("Manage processes to exclude from the tunnel")
.setting(clap::AppSettings::SubcommandRequiredElseHelp)
- .subcommand(
- clap::SubCommand::with_name("add").arg(clap::Arg::with_name("pid").required(true)),
- )
- .subcommand(
- clap::SubCommand::with_name("delete").arg(clap::Arg::with_name("pid").required(true)),
- )
- .subcommand(clap::SubCommand::with_name("clear"))
- .subcommand(clap::SubCommand::with_name("list"))
+ .subcommand(clap::App::new("add").arg(clap::Arg::new("pid").required(true)))
+ .subcommand(clap::App::new("delete").arg(clap::Arg::new("pid").required(true)))
+ .subcommand(clap::App::new("clear"))
+ .subcommand(clap::App::new("list"))
}
impl SplitTunnel {
- async fn handle_pid_cmd(matches: &clap::ArgMatches<'_>) -> Result<()> {
+ async fn handle_pid_cmd(matches: &clap::ArgMatches) -> Result<()> {
match matches.subcommand() {
- ("add", Some(matches)) => {
- let pid = value_t_or_exit!(matches.value_of("pid"), i32);
+ Some(("add", matches)) => {
+ let pid: i32 = matches.value_of_t_or_exit("pid");
new_rpc_client()
.await?
.add_split_tunnel_process(pid)
.await?;
Ok(())
}
- ("delete", Some(matches)) => {
- let pid = value_t_or_exit!(matches.value_of("pid"), i32);
+ Some(("delete", matches)) => {
+ let pid: i32 = matches.value_of_t_or_exit("pid");
new_rpc_client()
.await?
.remove_split_tunnel_process(pid)
.await?;
Ok(())
}
- ("clear", Some(_)) => {
+ Some(("clear", _)) => {
new_rpc_client()
.await?
.clear_split_tunnel_processes(())
.await?;
Ok(())
}
- ("list", Some(_)) => {
+ Some(("list", _)) => {
let mut pids_stream = new_rpc_client()
.await?
.get_split_tunnel_processes(())
diff --git a/mullvad-cli/src/cmds/split_tunnel/windows.rs b/mullvad-cli/src/cmds/split_tunnel/windows.rs
index 402186a77c..0bc8d468bc 100644
--- a/mullvad-cli/src/cmds/split_tunnel/windows.rs
+++ b/mullvad-cli/src/cmds/split_tunnel/windows.rs
@@ -1,5 +1,4 @@
use crate::{new_rpc_client, Command, Result};
-use clap::value_t_or_exit;
pub struct SplitTunnel;
@@ -9,29 +8,29 @@ impl Command for SplitTunnel {
"split-tunnel"
}
- fn clap_subcommand(&self) -> clap::App<'static, 'static> {
- clap::SubCommand::with_name(self.name())
+ fn clap_subcommand(&self) -> clap::App<'static> {
+ clap::App::new(self.name())
.about("Set options for applications to exclude from the tunnel")
.setting(clap::AppSettings::SubcommandRequiredElseHelp)
.subcommand(create_app_subcommand())
.subcommand(
- clap::SubCommand::with_name("set")
+ clap::App::new("set")
.about("Enable or disable split tunnel")
.arg(
- clap::Arg::with_name("policy")
+ clap::Arg::new("policy")
.required(true)
.possible_values(&["on", "off"]),
),
)
- .subcommand(clap::SubCommand::with_name("get").about("Display the split tunnel status"))
+ .subcommand(clap::App::new("get").about("Display the split tunnel status"))
}
- async fn run(&self, matches: &clap::ArgMatches<'_>) -> Result<()> {
+ async fn run(&self, matches: &clap::ArgMatches) -> Result<()> {
match matches.subcommand() {
- ("app", Some(matches)) => Self::handle_app_subcommand(matches).await,
- ("get", _) => self.get().await,
- ("set", Some(matches)) => {
- let enabled = value_t_or_exit!(matches.value_of("policy"), String);
+ Some(("app", matches)) => Self::handle_app_subcommand(matches).await,
+ Some(("get", _)) => self.get().await,
+ Some(("set", matches)) => {
+ let enabled = matches.value_of("policy").expect("missing policy");
self.set(enabled == "on").await
}
_ => {
@@ -41,24 +40,20 @@ impl Command for SplitTunnel {
}
}
-fn create_app_subcommand() -> clap::App<'static, 'static> {
- clap::SubCommand::with_name("app")
+fn create_app_subcommand() -> clap::App<'static> {
+ clap::App::new("app")
.about("Manage applications to exclude from the tunnel")
.setting(clap::AppSettings::SubcommandRequiredElseHelp)
- .subcommand(clap::SubCommand::with_name("list"))
- .subcommand(
- clap::SubCommand::with_name("add").arg(clap::Arg::with_name("path").required(true)),
- )
- .subcommand(
- clap::SubCommand::with_name("remove").arg(clap::Arg::with_name("path").required(true)),
- )
- .subcommand(clap::SubCommand::with_name("clear"))
+ .subcommand(clap::App::new("list"))
+ .subcommand(clap::App::new("add").arg(clap::Arg::new("path").required(true)))
+ .subcommand(clap::App::new("remove").arg(clap::Arg::new("path").required(true)))
+ .subcommand(clap::App::new("clear"))
}
impl SplitTunnel {
- async fn handle_app_subcommand(matches: &clap::ArgMatches<'_>) -> Result<()> {
+ async fn handle_app_subcommand(matches: &clap::ArgMatches) -> Result<()> {
match matches.subcommand() {
- ("list", Some(_)) => {
+ Some(("list", _)) => {
let paths = new_rpc_client()
.await?
.get_settings(())
@@ -75,20 +70,20 @@ impl SplitTunnel {
Ok(())
}
- ("add", Some(matches)) => {
- let path = value_t_or_exit!(matches.value_of("path"), String);
+ Some(("add", matches)) => {
+ let path: String = matches.value_of_t_or_exit("path");
new_rpc_client().await?.add_split_tunnel_app(path).await?;
Ok(())
}
- ("remove", Some(matches)) => {
- let path = value_t_or_exit!(matches.value_of("path"), String);
+ Some(("remove", matches)) => {
+ let path: String = matches.value_of_t_or_exit("path");
new_rpc_client()
.await?
.remove_split_tunnel_app(path)
.await?;
Ok(())
}
- ("clear", Some(_)) => {
+ Some(("clear", _)) => {
new_rpc_client().await?.clear_split_tunnel_apps(()).await?;
Ok(())
}