mirror of
https://github.com/AleoHQ/leo.git
synced 2025-01-04 16:15:11 +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
|
// 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/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{cli::CLI, cli_types::*};
|
use crate::{cli::CLI, cli_types::*, updater::Updater};
|
||||||
|
|
||||||
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";
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct UpdateCommand;
|
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 {
|
impl CLI for UpdateCommand {
|
||||||
type Options = (bool,);
|
type Options = (bool,);
|
||||||
type Output = ();
|
type Output = ();
|
||||||
@ -81,14 +41,14 @@ impl CLI for UpdateCommand {
|
|||||||
let _enter = span.enter();
|
let _enter = span.enter();
|
||||||
|
|
||||||
match options {
|
match options {
|
||||||
(true,) => match UpdateCommand::show_available_releases() {
|
(true,) => match Updater::show_available_releases() {
|
||||||
Ok(_) => return Ok(()),
|
Ok(_) => return Ok(()),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
tracing::error!("Could not fetch that latest version of Leo");
|
tracing::error!("Could not fetch that latest version of Leo");
|
||||||
tracing::error!("{}", e);
|
tracing::error!("{}", e);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
(false,) => match UpdateCommand::update_to_latest_release(true) {
|
(false,) => match Updater::update_to_latest_release(true) {
|
||||||
Ok(status) => {
|
Ok(status) => {
|
||||||
if status.uptodate() {
|
if status.uptodate() {
|
||||||
tracing::info!("Leo is already on the latest version: {}", status.version());
|
tracing::info!("Leo is already on the latest version: {}", status.version());
|
||||||
|
@ -152,6 +152,13 @@ impl_cli_error!(
|
|||||||
ZipFileError
|
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 {
|
impl From<leo_compiler::errors::CompilerError> for CLIError {
|
||||||
fn from(error: leo_compiler::errors::CompilerError) -> Self {
|
fn from(error: leo_compiler::errors::CompilerError) -> Self {
|
||||||
tracing::error!("{}\n", error);
|
tracing::error!("{}\n", error);
|
||||||
|
Loading…
Reference in New Issue
Block a user