leo_lang/cli/commands/
update.rs1use super::*;
18use crate::cli::helpers::updater::Updater;
19
20#[derive(Debug, Parser)]
22pub struct LeoUpdate {
23 #[clap(short = 'l', long, help = "List all available releases.")]
25 list: bool,
26 #[clap(short = 'n', long, help = "An optional release name.")]
28 name: Option<String>,
29 #[clap(short = 'q', long, help = "Suppress download logs.")]
31 quiet: bool,
32}
33
34impl Command for LeoUpdate {
35 type Input = ();
36 type Output = ();
37
38 fn log_span(&self) -> Span {
39 tracing::span!(tracing::Level::INFO, "Leo")
40 }
41
42 fn prelude(&self, _: Context) -> Result<Self::Input> {
43 Ok(())
44 }
45
46 fn apply(self, _: Context, _: Self::Input) -> Result<Self::Output>
47 where
48 Self: Sized,
49 {
50 match self.list {
51 true => match Updater::show_available_releases() {
52 Ok(output) => tracing::info!("{output}"),
53 Err(error) => tracing::info!("Failed to list the available versions of Leo\n{error}\n"),
54 },
55 false => {
56 let show_output = !self.quiet;
57 let result = Updater::update(show_output, self.name.clone());
58 if show_output {
59 match &result {
60 Ok(status) => {
61 if status.uptodate() {
62 tracing::info!("\nLeo is already on the latest version")
63 } else if status.updated() {
64 tracing::info!("\nLeo has updated to version {}", status.version())
65 }
66 }
67 Err(e) => tracing::info!("\nFailed to update Leo to the latest version\n{e}\n"),
68 }
69 }
70 if result.is_ok() {
71 Updater::update_bundled_plugins(show_output, self.name.as_deref());
72 }
73 }
74 }
75 Ok(())
76 }
77}