use crate::helpers::Updater;
use anyhow::Result;
use clap::Parser;
#[derive(Debug, Parser)]
pub enum Update {
Update {
#[clap(short = 'l', long)]
list: bool,
#[clap(short = 'q', long)]
quiet: bool,
},
}
impl Update {
pub fn parse(self) -> Result<String> {
match self {
Self::Update { list, quiet } => match list {
true => match Updater::show_available_releases() {
Ok(output) => Ok(output),
Err(error) => Ok(format!("Failed to list the available versions of Aleo\n{error}\n")),
},
false => {
let result = Updater::update_to_latest_release(!quiet);
if !quiet {
match result {
Ok(status) => {
if status.uptodate() {
Ok("\nAleo is already on the latest version".to_string())
} else if status.updated() {
Ok(format!("\nAleo has updated to version {}", status.version()))
} else {
Ok(String::new())
}
}
Err(e) => Ok(format!("\nFailed to update Aleo to the latest version\n{e}\n")),
}
} else {
Ok(String::new())
}
}
},
}
}
}