diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2018-09-04 09:34:08 -0300 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2018-09-05 07:08:21 -0300 |
| commit | d9e4e74af308b3644215c44ee9f729650a991124 (patch) | |
| tree | 2ad0034bda4cafb117ffd1e89d210e875dcda391 | |
| parent | 6ed7fb2d27144e7733fcd739c11cfc111dc5949c (diff) | |
| download | mullvadvpn-d9e4e74af308b3644215c44ee9f729650a991124.tar.xz mullvadvpn-d9e4e74af308b3644215c44ee9f729650a991124.zip | |
Set Enable IPv6 option as a common tunnel option
| -rw-r--r-- | mullvad-cli/src/cmds/tunnel.rs | 49 |
1 files changed, 30 insertions, 19 deletions
diff --git a/mullvad-cli/src/cmds/tunnel.rs b/mullvad-cli/src/cmds/tunnel.rs index c62755f493..3190800490 100644 --- a/mullvad-cli/src/cmds/tunnel.rs +++ b/mullvad-cli/src/cmds/tunnel.rs @@ -21,13 +21,6 @@ impl Command for Tunnel { .subcommand( clap::SubCommand::with_name("set") .subcommand( - clap::SubCommand::with_name("ipv6").arg( - clap::Arg::with_name("enable") - .required(true) - .takes_value(true) - .possible_values(&["on", "off"]), - ), - ).subcommand( clap::SubCommand::with_name("mssfix").arg( clap::Arg::with_name("mssfix") .help( @@ -40,12 +33,24 @@ impl Command for Tunnel { clap::SubCommand::with_name("get") .help("Retrieves the current setting for mssfix"), ), + ).subcommand( + clap::SubCommand::with_name("set") + .subcommand( + clap::SubCommand::with_name("ipv6").arg( + clap::Arg::with_name("enable") + .required(true) + .takes_value(true) + .possible_values(&["on", "off"]), + ), + ).setting(clap::AppSettings::SubcommandRequired), ) } fn run(&self, matches: &clap::ArgMatches) -> Result<()> { if let Some(openvpn_matches) = matches.subcommand_matches("openvpn") { Self::handle_openvpn_cmd(openvpn_matches) + } else if let Some(set_matches) = matches.subcommand_matches("set") { + Self::set_tunnel_option(set_matches) } else { unreachable!("No tunnel command given") } @@ -53,6 +58,23 @@ impl Command for Tunnel { } impl Tunnel { + fn set_tunnel_option(matches: &clap::ArgMatches) -> Result<()> { + if let Some(ipv6_args) = matches.subcommand_matches("ipv6") { + Self::set_enable_ipv6_option(ipv6_args) + } else { + unreachable!("Invalid option passed to 'tunnel set'"); + } + } + + fn set_enable_ipv6_option(args: &clap::ArgMatches) -> Result<()> { + let enabled = args.value_of("enable").unwrap() == "on"; + + let mut rpc = new_rpc_client()?; + rpc.set_openvpn_enable_ipv6(enabled)?; + println!("enable_ipv6 parameter updated"); + Ok(()) + } + fn handle_openvpn_cmd(matches: &clap::ArgMatches) -> Result<()> { if let Some(set_matches) = matches.subcommand_matches("set") { Self::set_openvpn_option(set_matches) @@ -67,24 +89,13 @@ impl Tunnel { } fn set_openvpn_option(matches: &clap::ArgMatches) -> Result<()> { - if let Some(ipv6_args) = matches.subcommand_matches("ipv6") { - Self::set_openvpn_enable_ipv6_option(ipv6_args) - } else if let Some(mssfix_args) = matches.subcommand_matches("mssfix") { + if let Some(mssfix_args) = matches.subcommand_matches("mssfix") { Self::set_openvpn_mssfix_option(mssfix_args) } else { unreachable!("Invalid option passed to 'openvpn set'"); } } - fn set_openvpn_enable_ipv6_option(args: &clap::ArgMatches) -> Result<()> { - let enabled = args.value_of("enable").unwrap() == "on"; - - let mut rpc = new_rpc_client()?; - rpc.set_openvpn_enable_ipv6(enabled)?; - println!("enable_ipv6 parameter updated"); - Ok(()) - } - fn set_openvpn_mssfix_option(args: &clap::ArgMatches) -> Result<()> { let mssfix_str = args.value_of("mssfix").unwrap(); let mssfix: Option<u16> = if mssfix_str == "" { |
