summaryrefslogtreecommitdiffhomepage
path: root/mullvad-cli/src/cmds/beta_program.rs
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2020-03-03 17:40:51 +0100
committerDavid Lönnhager <david.l@mullvad.net>2020-03-11 12:11:10 +0100
commit12e7344fb8eb1d9070895184105a94dc96d4b2b4 (patch)
tree6f01baedc1dfaf85358d518c623712cbee34ba19 /mullvad-cli/src/cmds/beta_program.rs
parent93175648ddb1187e5f5a79b9c2fea0334f406fbb (diff)
downloadmullvadvpn-12e7344fb8eb1d9070895184105a94dc96d4b2b4.tar.xz
mullvadvpn-12e7344fb8eb1d9070895184105a94dc96d4b2b4.zip
Beta program option in CLI
Diffstat (limited to 'mullvad-cli/src/cmds/beta_program.rs')
-rw-r--r--mullvad-cli/src/cmds/beta_program.rs54
1 files changed, 54 insertions, 0 deletions
diff --git a/mullvad-cli/src/cmds/beta_program.rs b/mullvad-cli/src/cmds/beta_program.rs
new file mode 100644
index 0000000000..c63027ccfd
--- /dev/null
+++ b/mullvad-cli/src/cmds/beta_program.rs
@@ -0,0 +1,54 @@
+use crate::{new_rpc_client, Command, Result};
+use clap::value_t_or_exit;
+
+pub struct BetaProgram;
+
+impl Command for BetaProgram {
+ fn name(&self) -> &'static str {
+ "beta-program"
+ }
+
+ fn clap_subcommand(&self) -> clap::App<'static, 'static> {
+ clap::SubCommand::with_name(self.name())
+ .about("Receive notifications about beta updates")
+ .setting(clap::AppSettings::SubcommandRequiredElseHelp)
+ .subcommand(
+ clap::SubCommand::with_name("set")
+ .about("Change beta notifications setting")
+ .arg(
+ clap::Arg::with_name("policy")
+ .required(true)
+ .possible_values(&["on", "off"]),
+ ),
+ )
+ .subcommand(clap::SubCommand::with_name("get").about("Get beta notifications setting"))
+ }
+
+ fn run(&self, matches: &clap::ArgMatches<'_>) -> Result<()> {
+ match matches.subcommand() {
+ ("get", Some(_)) => {
+ let mut rpc = new_rpc_client()?;
+ let settings = rpc.get_settings()?;
+ let enabled_str = if settings.get_show_beta_releases().unwrap_or(false) {
+ "on"
+ } else {
+ "off"
+ };
+ println!("Beta program: {}", enabled_str);
+ Ok(())
+ }
+ ("set", Some(matches)) => {
+ let enabled_str = value_t_or_exit!(matches.value_of("policy"), String);
+
+ let mut rpc = new_rpc_client()?;
+ rpc.set_show_beta_releases(enabled_str == "on")?;
+
+ println!("Beta program: {}", enabled_str);
+ Ok(())
+ }
+ _ => {
+ unreachable!("unhandled comand");
+ }
+ }
+ }
+}