summaryrefslogtreecommitdiffhomepage
path: root/mullvad-cli/src/cmds/beta_program.rs
blob: 77aa73ace3ef9e8b9bb0e00ef102aa6505c9a6af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use crate::{new_rpc_client, Command, Error, Result};

pub struct BetaProgram;

#[mullvad_management_interface::async_trait]
impl Command for BetaProgram {
    fn name(&self) -> &'static str {
        "beta-program"
    }

    fn clap_subcommand(&self) -> clap::App<'static> {
        clap::App::new(self.name())
            .about("Receive notifications about beta updates")
            .setting(clap::AppSettings::SubcommandRequiredElseHelp)
            .subcommand(
                clap::App::new("set")
                    .about("Change beta notifications setting")
                    .arg(
                        clap::Arg::new("policy")
                            .required(true)
                            .possible_values(["on", "off"]),
                    ),
            )
            .subcommand(clap::App::new("get").about("Get beta notifications setting"))
    }

    async fn run(&self, matches: &clap::ArgMatches) -> Result<()> {
        match matches.subcommand() {
            Some(("get", _)) => {
                let mut rpc = new_rpc_client().await?;
                let settings = rpc.get_settings(()).await?.into_inner();
                let enabled_str = if settings.show_beta_releases {
                    "on"
                } else {
                    "off"
                };
                println!("Beta program: {enabled_str}");
                Ok(())
            }
            Some(("set", matches)) => {
                let enable_str = matches.value_of("policy").expect("missing policy");
                let enable = enable_str == "on";

                if !enable && mullvad_version::VERSION.contains("beta") {
                    return Err(Error::InvalidCommand(
                        "The beta program must be enabled while running a beta version",
                    ));
                }

                let mut rpc = new_rpc_client().await?;
                rpc.set_show_beta_releases(enable).await?;

                println!("Beta program: {enable_str}");
                Ok(())
            }
            _ => {
                unreachable!("unhandled command");
            }
        }
    }
}