use crate::cli::Updater;
use anyhow::Result;
use clap::Parser;
#[derive(Debug, Parser)]
#[clap(name = "snarkVM", author = "The Aleo Team <hello@aleo.org>", setting = clap::AppSettings::ColoredHelp)]
pub struct CLI {
#[clap(default_value = "2", short, long)]
pub verbosity: u8,
#[clap(subcommand)]
pub command: Command,
}
#[derive(Debug, Parser)]
pub enum Command {
Update {
#[clap(short = 'l', long)]
list: bool,
#[clap(short = 'q', long)]
quiet: bool,
},
}
impl Command {
pub fn start(&self) -> Result<String> {
match self {
Command::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 snarkVM\n{error}\n")),
},
false => {
let result = Updater::update_to_latest_release(!quiet);
if !quiet {
match result {
Ok(status) => {
if status.uptodate() {
Ok("\nsnarkVM is already on the latest version".to_string())
} else if status.updated() {
Ok(format!("\nsnarkVM has updated to version {}", status.version()))
} else {
Ok("".to_string())
}
}
Err(e) => Ok(format!("\nFailed to update snarkVM to the latest version\n{}\n", e)),
}
} else {
Ok("".to_string())
}
}
}, }
}
}