nimbus_cli/updater/
mod.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
5mod taskcluster;
6
7use std::io::Write;
8use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};
9
10pub(crate) fn check_for_update() {
11    if std::env::var("NIMBUS_CLI_SUPPRESS_UPDATE_CHECK").is_ok() {
12        return;
13    }
14    if let Some((curr, next)) = taskcluster::check_taskcluster_for_update() {
15        _ = print_update_instructions(&curr, &next);
16    }
17}
18
19fn print_update_instructions(curr: &str, next: &str) -> std::io::Result<()> {
20    let mut stderr = StandardStream::stderr(ColorChoice::Auto);
21
22    stderr.set_color(ColorSpec::new().set_fg(Some(Color::Green)))?;
23    writeln!(&mut stderr, "An update is available: {} --> {}", curr, next)?;
24
25    cfg_if::cfg_if! {
26        if #[cfg(windows)] {
27            writeln!(&mut stderr, "To update follow the instructions at https://experimenter.info/nimbus-cli/install")?;
28        } else {
29            writeln!(&mut stderr, "Up update, run this command:")?;
30            stderr.set_color(ColorSpec::new().set_fg(Some(Color::Yellow)))?;
31            writeln!(&mut stderr, "  curl https://raw.githubusercontent.com/mozilla/application-services/main/install-nimbus-cli.sh | bash")?;
32        }
33    }
34
35    stderr.reset()?;
36
37    Ok(())
38}