romm_cli/commands/
update.rs1use crate::cli_presentation::CliPresentation;
2use crate::core::interrupt::InterruptContext;
3use crate::update::{self, ApplyUpdateOptions, ApplyUpdateOutcome};
4use anyhow::Result;
5use serde::Serialize;
6
7#[derive(Serialize)]
8struct UpdateJsonOutcome {
9 status: &'static str,
10 version: String,
11}
12
13pub async fn handle(
15 presentation: CliPresentation,
16 interrupt: Option<InterruptContext>,
17) -> Result<()> {
18 let options = ApplyUpdateOptions {
19 show_progress: presentation.shows_progress(),
20 show_output: presentation.is_text(),
21 no_confirm: true,
22 target_version_tag: None,
23 };
24 match update::apply_update(interrupt, options).await? {
25 ApplyUpdateOutcome::Updated(version) => {
26 if presentation.is_json() {
27 let out = UpdateJsonOutcome {
28 status: "updated",
29 version: version.clone(),
30 };
31 println!("{}", serde_json::to_string_pretty(&out)?);
32 } else {
33 println!("Updated successfully to `{version}`.");
34 println!("Restart romm-cli to use the new version.");
35 }
36 }
37 ApplyUpdateOutcome::UpToDate(version) => {
38 if presentation.is_json() {
39 let out = UpdateJsonOutcome {
40 status: "up_to_date",
41 version: version.clone(),
42 };
43 println!("{}", serde_json::to_string_pretty(&out)?);
44 } else {
45 println!("Already up to date (`{version}`).");
46 }
47 }
48 }
49 Ok(())
50}