snarkvm_debug/cli/commands/update.rs
1// Copyright (C) 2019-2023 Aleo Systems Inc.
2// This file is part of the snarkVM library.
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at:
7// http://www.apache.org/licenses/LICENSE-2.0
8
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use super::*;
16use crate::cli::helpers::Updater;
17
18/// Update SnarkVM to the latest version
19#[derive(Debug, Parser)]
20pub struct Update {
21 /// Lists all available versions of Aleo
22 #[clap(short = 'l', long)]
23 list: bool,
24 /// Suppress outputs to terminal
25 #[clap(short = 'q', long)]
26 quiet: bool,
27}
28
29impl Update {
30 pub fn parse(self) -> Result<String> {
31 match self.list {
32 true => match Updater::show_available_releases() {
33 Ok(output) => Ok(output),
34 Err(error) => Ok(format!("Failed to list the available versions of Aleo\n{error}\n")),
35 },
36 false => {
37 let result = Updater::update_to_latest_release(!self.quiet);
38 if !self.quiet {
39 match result {
40 Ok(status) => {
41 if status.uptodate() {
42 Ok("\nAleo is already on the latest version".to_string())
43 } else if status.updated() {
44 Ok(format!("\nAleo has updated to version {}", status.version()))
45 } else {
46 Ok(String::new())
47 }
48 }
49 Err(e) => Ok(format!("\nFailed to update Aleo to the latest version\n{e}\n")),
50 }
51 } else {
52 Ok(String::new())
53 }
54 }
55 }
56 }
57}