mirror of
https://github.com/AleoHQ/leo.git
synced 2024-12-30 05:02:04 +03:00
Merge pull request #473 from AleoHQ/fix/update-handler
Fix early halting of leo commands due to updater checks
This commit is contained in:
commit
4682d05e58
@ -19,3 +19,6 @@ pub use self::cli::*;
|
||||
|
||||
pub mod commands;
|
||||
pub use self::commands::*;
|
||||
|
||||
pub mod updater;
|
||||
pub use self::updater::*;
|
||||
|
31
leo/errors/updater.rs
Normal file
31
leo/errors/updater.rs
Normal file
@ -0,0 +1,31 @@
|
||||
// Copyright (C) 2019-2020 Aleo Systems Inc.
|
||||
// This file is part of the Leo library.
|
||||
|
||||
// The Leo library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// The Leo library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum UpdaterError {
|
||||
#[error("{}: {}", _0, _1)]
|
||||
Crate(&'static str, String),
|
||||
|
||||
#[error("The current version {} is more recent than the release version {}", _0, _1)]
|
||||
OldReleaseVersion(String, String),
|
||||
}
|
||||
|
||||
impl From<self_update::errors::Error> for UpdaterError {
|
||||
fn from(error: self_update::errors::Error) -> Self {
|
||||
tracing::error!("{}\n", error);
|
||||
UpdaterError::Crate("self_update", error.to_string())
|
||||
}
|
||||
}
|
@ -13,7 +13,7 @@
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
use crate::config::Config;
|
||||
use crate::{config::Config, errors::UpdaterError};
|
||||
|
||||
use colored::Colorize;
|
||||
use self_update::{backends::github, version::bump_is_greater, Status};
|
||||
@ -27,7 +27,7 @@ impl Updater {
|
||||
const LEO_REPO_OWNER: &'static str = "AleoHQ";
|
||||
|
||||
/// Show all available releases for `leo`.
|
||||
pub fn show_available_releases() -> Result<(), self_update::errors::Error> {
|
||||
pub fn show_available_releases() -> Result<(), UpdaterError> {
|
||||
let releases = github::ReleaseList::configure()
|
||||
.repo_owner(Self::LEO_REPO_OWNER)
|
||||
.repo_name(Self::LEO_REPO_NAME)
|
||||
@ -42,7 +42,7 @@ impl Updater {
|
||||
}
|
||||
|
||||
/// Update `leo` to the latest release.
|
||||
pub fn update_to_latest_release(show_output: bool) -> Result<Status, self_update::errors::Error> {
|
||||
pub fn update_to_latest_release(show_output: bool) -> Result<Status, UpdaterError> {
|
||||
let status = github::Update::configure()
|
||||
.repo_owner(Self::LEO_REPO_OWNER)
|
||||
.repo_name(Self::LEO_REPO_NAME)
|
||||
@ -58,7 +58,7 @@ impl Updater {
|
||||
}
|
||||
|
||||
/// Check if there is an available update for `leo` and return the newest release.
|
||||
pub fn update_available() -> Result<Option<String>, self_update::errors::Error> {
|
||||
pub fn update_available() -> Result<String, UpdaterError> {
|
||||
let updater = github::Update::configure()
|
||||
.repo_owner(Self::LEO_REPO_OWNER)
|
||||
.repo_name(Self::LEO_REPO_NAME)
|
||||
@ -70,9 +70,9 @@ impl Updater {
|
||||
let latest_release = updater.get_latest_release()?;
|
||||
|
||||
if bump_is_greater(¤t_version, &latest_release.version)? {
|
||||
Ok(Some(latest_release.version))
|
||||
Ok(latest_release.version)
|
||||
} else {
|
||||
Ok(None)
|
||||
Err(UpdaterError::OldReleaseVersion(current_version, latest_release.version))
|
||||
}
|
||||
}
|
||||
|
||||
@ -89,7 +89,7 @@ impl Updater {
|
||||
}
|
||||
} else {
|
||||
// If the auto update configuration is off, notify the user to update leo.
|
||||
if let Some(latest_version) = Self::update_available().unwrap() {
|
||||
if let Ok(latest_version) = Self::update_available() {
|
||||
let mut message = "🟢 A new version is available! Run".bold().green().to_string();
|
||||
message += &" `leo update` ".bold().white();
|
||||
message += &format!("to update to v{}.", latest_version).bold().green();
|
||||
|
Loading…
Reference in New Issue
Block a user