summaryrefslogtreecommitdiffhomepage
path: root/mullvad-cli/src/cmds/version.rs
blob: 08944f921b700bb9f1e04907bf29e0c1e3ad41e0 (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
use crate::{new_rpc_client, Command, Error, Result};

pub struct Version;

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

    fn clap_subcommand(&self) -> clap::App<'static, 'static> {
        clap::SubCommand::with_name(self.name())
            .about("Shows current version, and the currently supported versions")
    }

    async fn run(&self, _: &clap::ArgMatches<'_>) -> Result<()> {
        let mut rpc = new_rpc_client().await?;
        let current_version = rpc
            .get_current_version(())
            .await
            .map_err(|error| Error::RpcFailedExt("Failed to obtain current version", error))?
            .into_inner();
        println!("Current version: {}", current_version);
        let version_info = rpc
            .get_version_info(())
            .await
            .map_err(|error| Error::RpcFailedExt("Failed to obtain version info", error))?
            .into_inner();
        println!("\tIs supported: {}", version_info.supported);

        if !version_info.suggested_upgrade.is_empty() {
            println!("\tSuggested update: {}", version_info.suggested_upgrade);
        } else {
            println!("\tNo newer version is available");
        }

        if !version_info.latest_stable.is_empty() {
            println!("\tLatest stable version: {}", version_info.latest_stable);
        }

        let settings = rpc.get_settings(()).await?.into_inner();
        if settings.show_beta_releases {
            println!("\tLatest beta version: {}", version_info.latest_beta);
        };

        Ok(())
    }
}