mirror of
https://github.com/AleoHQ/leo.git
synced 2025-01-02 06:50:13 +03:00
Use updater for leo update cli
This commit is contained in:
parent
e320d68aea
commit
a2a0eca892
@ -14,51 +14,11 @@
|
||||
// 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::{cli::CLI, cli_types::*};
|
||||
|
||||
use self_update::{backends::github, cargo_crate_version, Status};
|
||||
|
||||
const LEO_BIN_NAME: &str = "leo";
|
||||
const LEO_REPO_OWNER: &str = "AleoHQ";
|
||||
const LEO_REPO_NAME: &str = "leo";
|
||||
use crate::{cli::CLI, cli_types::*, updater::Updater};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct UpdateCommand;
|
||||
|
||||
// TODO Add logic for users to easily select release versions.
|
||||
impl UpdateCommand {
|
||||
/// Show all available releases for `leo`
|
||||
pub fn show_available_releases() -> Result<(), self_update::errors::Error> {
|
||||
let releases = github::ReleaseList::configure()
|
||||
.repo_owner(LEO_REPO_OWNER)
|
||||
.repo_name(LEO_REPO_NAME)
|
||||
.build()?
|
||||
.fetch()?;
|
||||
|
||||
tracing::info!("List of available Leo's versions");
|
||||
for release in releases {
|
||||
tracing::info!("* {}", release.version);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Update `leo` to the latest release
|
||||
pub fn update_to_latest_release(show_output: bool) -> Result<Status, self_update::errors::Error> {
|
||||
let status = github::Update::configure()
|
||||
.repo_owner(LEO_REPO_OWNER)
|
||||
.repo_name(LEO_REPO_NAME)
|
||||
.bin_name(LEO_BIN_NAME)
|
||||
.current_version(cargo_crate_version!())
|
||||
.show_download_progress(true)
|
||||
.no_confirm(true)
|
||||
.show_output(show_output)
|
||||
.build()?
|
||||
.update()?;
|
||||
|
||||
Ok(status)
|
||||
}
|
||||
}
|
||||
|
||||
impl CLI for UpdateCommand {
|
||||
type Options = (bool,);
|
||||
type Output = ();
|
||||
@ -81,14 +41,14 @@ impl CLI for UpdateCommand {
|
||||
let _enter = span.enter();
|
||||
|
||||
match options {
|
||||
(true,) => match UpdateCommand::show_available_releases() {
|
||||
(true,) => match Updater::show_available_releases() {
|
||||
Ok(_) => return Ok(()),
|
||||
Err(e) => {
|
||||
tracing::error!("Could not fetch that latest version of Leo");
|
||||
tracing::error!("{}", e);
|
||||
}
|
||||
},
|
||||
(false,) => match UpdateCommand::update_to_latest_release(true) {
|
||||
(false,) => match Updater::update_to_latest_release(true) {
|
||||
Ok(status) => {
|
||||
if status.uptodate() {
|
||||
tracing::info!("Leo is already on the latest version: {}", status.version());
|
||||
|
@ -152,6 +152,13 @@ impl_cli_error!(
|
||||
ZipFileError
|
||||
);
|
||||
|
||||
impl From<clap::Error> for CLIError {
|
||||
fn from(error: clap::Error) -> Self {
|
||||
tracing::error!("{}\n", error);
|
||||
CLIError::Crate("clap", format!("{}", error))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<leo_compiler::errors::CompilerError> for CLIError {
|
||||
fn from(error: leo_compiler::errors::CompilerError) -> Self {
|
||||
tracing::error!("{}\n", error);
|
||||
|
Loading…
Reference in New Issue
Block a user