From ba3c0872f4ddd21ee1e461a867131762b2eb335a Mon Sep 17 00:00:00 2001 From: raychu86 Date: Fri, 21 Aug 2020 16:28:08 -0700 Subject: [PATCH 1/4] Update auto update displays and confirmation prompts --- Cargo.lock | 261 +++++++++++------------------------------ leo/commands/update.rs | 9 +- leo/main.rs | 4 +- 3 files changed, 77 insertions(+), 197 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 01ad65165b..198bad71a5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1238,13 +1238,13 @@ dependencies = [ "rand_xorshift", "serde", "sha2", - "snarkos-curves 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "snarkos-curves", "snarkos-dpc", - "snarkos-errors 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "snarkos-errors", "snarkos-gadgets", - "snarkos-models 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "snarkos-objects 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "snarkos-utilities 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "snarkos-models", + "snarkos-objects", + "snarkos-utilities", "thiserror", ] @@ -1254,9 +1254,9 @@ version = "1.0.0" dependencies = [ "rand", "rand_xorshift", - "snarkos-errors 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "snarkos-models 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "snarkos-utilities 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "snarkos-errors", + "snarkos-models", + "snarkos-utilities", "thiserror", ] @@ -1268,11 +1268,11 @@ dependencies = [ "pest", "pest-ast", "pest_derive", - "snarkos-algorithms 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "snarkos-curves 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "snarkos-errors 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "snarkos-algorithms", + "snarkos-curves", + "snarkos-errors", "snarkos-gadgets", - "snarkos-models 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "snarkos-models", "thiserror", ] @@ -1303,12 +1303,12 @@ dependencies = [ "self_update", "serde", "serde_json", - "snarkos-algorithms 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "snarkos-curves 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "snarkos-errors 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "snarkos-algorithms", + "snarkos-curves", + "snarkos-errors", "snarkos-gadgets", - "snarkos-models 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "snarkos-utilities 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "snarkos-models", + "snarkos-utilities", "thiserror", "toml", "zip", @@ -1339,14 +1339,14 @@ dependencies = [ "leo-typed", "rand", "rand_xorshift", - "snarkos-algorithms 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "snarkos-curves 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "snarkos-algorithms", + "snarkos-curves", "snarkos-dpc", - "snarkos-errors 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "snarkos-models 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "snarkos-objects 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "snarkos-errors", + "snarkos-models", + "snarkos-objects", "snarkos-storage", - "snarkos-utilities 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "snarkos-utilities", "thiserror", ] @@ -1360,8 +1360,8 @@ dependencies = [ "pest", "serde", "serde_json", - "snarkos-errors 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "snarkos-models 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "snarkos-errors", + "snarkos-models", ] [[package]] @@ -2325,26 +2325,6 @@ version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fbee7696b84bbf3d89a1c2eccff0850e3047ed46bfcd2e92c29a2d074d57e252" -[[package]] -name = "snarkos-algorithms" -version = "1.0.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#9fda1b628c627bf717556e81dc10bee667f77a52" -dependencies = [ - "blake2", - "derivative", - "digest 0.8.1", - "itertools 0.9.0", - "rand", - "rand_chacha", - "rayon", - "sha2", - "smallvec", - "snarkos-errors 1.0.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", - "snarkos-models 1.0.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", - "snarkos-profiler 1.0.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", - "snarkos-utilities 1.0.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", -] - [[package]] name = "snarkos-algorithms" version = "1.0.0" @@ -2360,25 +2340,10 @@ dependencies = [ "rayon", "sha2", "smallvec", - "snarkos-errors 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "snarkos-models 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "snarkos-profiler 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "snarkos-utilities 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "snarkos-curves" -version = "1.0.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#9fda1b628c627bf717556e81dc10bee667f77a52" -dependencies = [ - "derivative", - "rand", - "rand_xorshift", - "rustc_version", - "serde", - "snarkos-errors 1.0.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", - "snarkos-models 1.0.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", - "snarkos-utilities 1.0.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-errors", + "snarkos-models", + "snarkos-profiler", + "snarkos-utilities", ] [[package]] @@ -2392,19 +2357,9 @@ dependencies = [ "rand_xorshift", "rustc_version", "serde", - "snarkos-errors 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "snarkos-models 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "snarkos-utilities 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "snarkos-derives" -version = "1.0.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#9fda1b628c627bf717556e81dc10bee667f77a52" -dependencies = [ - "proc-macro2 1.0.19", - "quote 1.0.7", - "syn 1.0.38", + "snarkos-errors", + "snarkos-models", + "snarkos-utilities", ] [[package]] @@ -2429,21 +2384,22 @@ dependencies = [ "hex", "itertools 0.9.0", "rand", - "snarkos-algorithms 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "snarkos-curves 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "snarkos-errors 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "snarkos-algorithms", + "snarkos-curves", + "snarkos-errors", "snarkos-gadgets", - "snarkos-models 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "snarkos-objects 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "snarkos-parameters 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "snarkos-profiler 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "snarkos-utilities 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "snarkos-models", + "snarkos-objects", + "snarkos-parameters", + "snarkos-profiler", + "snarkos-utilities", ] [[package]] name = "snarkos-errors" version = "1.0.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#9fda1b628c627bf717556e81dc10bee667f77a52" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45fbdc0916755cdf9522f6abc20103681f0d23308067b1a53be91fe216392d37" dependencies = [ "base58", "bech32", @@ -2456,21 +2412,6 @@ dependencies = [ "toml", ] -[[package]] -name = "snarkos-errors" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45fbdc0916755cdf9522f6abc20103681f0d23308067b1a53be91fe216392d37" -dependencies = [ - "base58", - "bech32", - "bincode", - "hex", - "jsonrpc-core", - "thiserror", - "toml", -] - [[package]] name = "snarkos-gadgets" version = "1.0.0" @@ -2480,27 +2421,11 @@ dependencies = [ "derivative", "digest 0.8.1", "itertools 0.9.0", - "snarkos-algorithms 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "snarkos-curves 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "snarkos-errors 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "snarkos-models 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "snarkos-utilities 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "snarkos-models" -version = "1.0.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#9fda1b628c627bf717556e81dc10bee667f77a52" -dependencies = [ - "bincode", - "derivative", - "itertools 0.9.0", - "rand", - "rand_xorshift", - "serde", - "smallvec", - "snarkos-errors 1.0.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", - "snarkos-utilities 1.0.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-algorithms", + "snarkos-curves", + "snarkos-errors", + "snarkos-models", + "snarkos-utilities", ] [[package]] @@ -2516,29 +2441,8 @@ dependencies = [ "rand_xorshift", "serde", "smallvec", - "snarkos-errors 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "snarkos-utilities 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "snarkos-objects" -version = "1.0.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#9fda1b628c627bf717556e81dc10bee667f77a52" -dependencies = [ - "base58", - "bech32", - "chrono", - "derivative", - "hex", - "once_cell", - "rand", - "serde", - "sha2", - "snarkos-algorithms 1.0.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", - "snarkos-curves 1.0.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", - "snarkos-errors 1.0.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", - "snarkos-models 1.0.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", - "snarkos-utilities 1.0.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-errors", + "snarkos-utilities", ] [[package]] @@ -2556,24 +2460,11 @@ dependencies = [ "rand", "serde", "sha2", - "snarkos-algorithms 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "snarkos-curves 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "snarkos-errors 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "snarkos-models 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "snarkos-utilities 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "snarkos-parameters" -version = "1.0.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#9fda1b628c627bf717556e81dc10bee667f77a52" -dependencies = [ - "curl", - "hex", - "snarkos-algorithms 1.0.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", - "snarkos-errors 1.0.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", - "snarkos-models 1.0.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", - "snarkos-utilities 1.0.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-algorithms", + "snarkos-curves", + "snarkos-errors", + "snarkos-models", + "snarkos-utilities", ] [[package]] @@ -2582,18 +2473,14 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec4f9d1db48ac8b784d2499af9619c0ee5b3c619ca9467dbf102804aba721873" dependencies = [ + "curl", "hex", - "snarkos-algorithms 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "snarkos-errors 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "snarkos-models 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "snarkos-utilities 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "snarkos-algorithms", + "snarkos-errors", + "snarkos-models", + "snarkos-utilities", ] -[[package]] -name = "snarkos-profiler" -version = "1.0.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#9fda1b628c627bf717556e81dc10bee667f77a52" - [[package]] name = "snarkos-profiler" version = "1.0.0" @@ -2603,7 +2490,8 @@ checksum = "7cf0f5fd8121285811d5b5f7c61e85e176c2ca55d8009e24e151308a7eaa0db6" [[package]] name = "snarkos-storage" version = "1.0.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#9fda1b628c627bf717556e81dc10bee667f77a52" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6763f78edd89f0694feeaaa51a16ad663ee7bdec17f88bc239ab121507f794f4" dependencies = [ "bincode", "hex", @@ -2611,23 +2499,12 @@ dependencies = [ "rand", "rocksdb", "serde", - "snarkos-algorithms 1.0.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", - "snarkos-errors 1.0.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", - "snarkos-models 1.0.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", - "snarkos-objects 1.0.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", - "snarkos-parameters 1.0.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", - "snarkos-utilities 1.0.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", -] - -[[package]] -name = "snarkos-utilities" -version = "1.0.0" -source = "git+ssh://git@github.com/AleoHQ/snarkOS.git#9fda1b628c627bf717556e81dc10bee667f77a52" -dependencies = [ - "bincode", - "rand", - "snarkos-derives 1.0.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", - "snarkos-errors 1.0.0 (git+ssh://git@github.com/AleoHQ/snarkOS.git)", + "snarkos-algorithms", + "snarkos-errors", + "snarkos-models", + "snarkos-objects", + "snarkos-parameters", + "snarkos-utilities", ] [[package]] @@ -2638,8 +2515,8 @@ checksum = "21ad2b96414c45c2f90e9344b1420c9db2fbbb9435d6f1da3e2f819da1b08c05" dependencies = [ "bincode", "rand", - "snarkos-derives 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "snarkos-errors 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "snarkos-derives", + "snarkos-errors", ] [[package]] diff --git a/leo/commands/update.rs b/leo/commands/update.rs index 0abc9cb160..46457dbe61 100644 --- a/leo/commands/update.rs +++ b/leo/commands/update.rs @@ -25,6 +25,7 @@ const LEO_REPO_NAME: &str = "leo"; #[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> { @@ -42,13 +43,15 @@ impl UpdateCommand { } /// Update `leo` to the latest release - pub fn update_to_latest_release() -> Result { + pub fn update_to_latest_release(show_output: bool) -> Result { let status = github::Update::configure() .repo_owner(LEO_REPO_OWNER) .repo_name(LEO_REPO_NAME) .bin_name(LEO_BIN_NAME) - .show_download_progress(true) .current_version(cargo_crate_version!()) + .show_download_progress(true) + .no_confirm(true) + .show_output(show_output) .build()? .update()?; @@ -81,7 +84,7 @@ impl CLI for UpdateCommand { log::error!("{}", e); } }, - (false,) => match UpdateCommand::update_to_latest_release() { + (false,) => match UpdateCommand::update_to_latest_release(true) { Ok(status) => { if status.uptodate() { log::info!("Leo is already on the latest version: {}", status.version()); diff --git a/leo/main.rs b/leo/main.rs index ed4d4473e4..a8cedaadd8 100644 --- a/leo/main.rs +++ b/leo/main.rs @@ -58,8 +58,8 @@ fn main() -> Result<(), CLIError> { let config = Config::read_config()?; - if config.auto_update { - if let Ok(status) = UpdateCommand::update_to_latest_release() { + if config.auto_update && arguments.subcommand().0 != "update" { + if let Ok(status) = UpdateCommand::update_to_latest_release(false) { if status.updated() { log::info!("Leo has successfully updated to version: {}", status.version()); } From e320d68aea907af74ab366ad72bd75602978117f Mon Sep 17 00:00:00 2001 From: raychu86 Date: Wed, 2 Sep 2020 17:19:23 -0700 Subject: [PATCH 2/4] Implement leo updater --- leo/lib.rs | 1 + leo/updater.rs | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 leo/updater.rs diff --git a/leo/lib.rs b/leo/lib.rs index 5de76c348c..1fa729229c 100644 --- a/leo/lib.rs +++ b/leo/lib.rs @@ -25,3 +25,4 @@ pub mod config; pub mod errors; pub mod logger; pub mod synthesizer; +pub mod updater; diff --git a/leo/updater.rs b/leo/updater.rs new file mode 100644 index 0000000000..5fdb7b01b0 --- /dev/null +++ b/leo/updater.rs @@ -0,0 +1,86 @@ +use crate::config::Config; + +use colored::Colorize; +use self_update::{backends::github, version::bump_is_greater, Status}; + +pub struct Updater; + +// TODO Add logic for users to easily select release versions. +impl Updater { + const LEO_BIN_NAME: &'static str = "leo"; + const LEO_REPO_NAME: &'static str = "leo"; + const LEO_REPO_OWNER: &'static str = "AleoHQ"; + + /// Show all available releases for `leo`. + pub fn show_available_releases() -> Result<(), self_update::errors::Error> { + let releases = github::ReleaseList::configure() + .repo_owner(Self::LEO_REPO_OWNER) + .repo_name(Self::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 { + let status = github::Update::configure() + .repo_owner(Self::LEO_REPO_OWNER) + .repo_name(Self::LEO_REPO_NAME) + .bin_name(Self::LEO_BIN_NAME) + .current_version(&include_str!("./leo-version").replace('v', "")) + .show_download_progress(true) + .no_confirm(true) + .show_output(show_output) + .build()? + .update()?; + + Ok(status) + } + + /// Check if there is an available update for `leo` and return the newest release. + pub fn update_available() -> Result, self_update::errors::Error> { + let updater = github::Update::configure() + .repo_owner(Self::LEO_REPO_OWNER) + .repo_name(Self::LEO_REPO_NAME) + .bin_name(Self::LEO_BIN_NAME) + .current_version(&include_str!("./leo-version").replace('v', "")) + .build()?; + + let current_version = updater.current_version(); + let latest_release = updater.get_latest_release()?; + + if bump_is_greater(¤t_version, &latest_release.version)? { + Ok(Some(latest_release.version)) + } else { + Ok(None) + } + } + + /// Display the CLI message, if the Leo configuration allows. + pub fn print_cli() { + let config = Config::read_config().unwrap(); + + if config.auto_update { + // If the auto update configuration is on, attempt to update the version. + if let Ok(status) = Self::update_to_latest_release(false) { + if status.updated() { + tracing::info!("Successfully updated to {}", status.version()); + } + } + } else { + // If the auto update configuration is off, notify the user to update leo. + if let Some(latest_version) = Self::update_available().unwrap() { + let mut message = format!("{}", "🟢 A new version is available! Run".bold().green()); + message += &format!("{}", " `leo update` ".bold().white()); + message += &format!("{}", &(format!("to update to v{}.", latest_version)).bold().green()); + + tracing::info!("\n{}\n", message); + } + } + } +} From a2a0eca892a213599396553ed63f622f41b87f18 Mon Sep 17 00:00:00 2001 From: raychu86 Date: Wed, 2 Sep 2020 17:20:11 -0700 Subject: [PATCH 3/4] Use updater for leo update cli --- leo/commands/update.rs | 46 +++--------------------------------------- leo/errors/cli.rs | 7 +++++++ 2 files changed, 10 insertions(+), 43 deletions(-) diff --git a/leo/commands/update.rs b/leo/commands/update.rs index 69fd44737e..27381f30c8 100644 --- a/leo/commands/update.rs +++ b/leo/commands/update.rs @@ -14,51 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -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 { - 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()); diff --git a/leo/errors/cli.rs b/leo/errors/cli.rs index ca160a609f..6a2c3b4f40 100644 --- a/leo/errors/cli.rs +++ b/leo/errors/cli.rs @@ -152,6 +152,13 @@ impl_cli_error!( ZipFileError ); +impl From for CLIError { + fn from(error: clap::Error) -> Self { + tracing::error!("{}\n", error); + CLIError::Crate("clap", format!("{}", error)) + } +} + impl From for CLIError { fn from(error: leo_compiler::errors::CompilerError) -> Self { tracing::error!("{}\n", error); From 3df54054836a79e039efa31b39db82d18711aab7 Mon Sep 17 00:00:00 2001 From: raychu86 Date: Wed, 2 Sep 2020 17:21:01 -0700 Subject: [PATCH 4/4] Integrate leo updater to cli --- leo/cli.rs | 6 +++++- leo/config.rs | 2 +- leo/main.rs | 32 +++++++++++++++++--------------- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/leo/cli.rs b/leo/cli.rs index 42f9b4683b..acad5a2f58 100644 --- a/leo/cli.rs +++ b/leo/cli.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{cli_types::*, errors::CLIError, logger}; +use crate::{cli_types::*, errors::CLIError, logger, updater::Updater}; use clap::{App, AppSettings, Arg, ArgMatches, SubCommand}; @@ -90,6 +90,10 @@ pub trait CLI { false => logger::init_logger("leo", 1), } + if arguments.subcommand().0 != "update" { + Updater::print_cli(); + } + let options = Self::parse(arguments)?; let _output = Self::output(options)?; Ok(()) diff --git a/leo/config.rs b/leo/config.rs index 48a041eba2..ff15ff4725 100644 --- a/leo/config.rs +++ b/leo/config.rs @@ -56,7 +56,7 @@ pub struct Config { impl Default for Config { fn default() -> Self { - Self { auto_update: true } + Self { auto_update: false } } } diff --git a/leo/main.rs b/leo/main.rs index 0ca48d96a5..7c8c124904 100644 --- a/leo/main.rs +++ b/leo/main.rs @@ -14,13 +14,13 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_lang::{cli::*, commands::*, config::Config, errors::CLIError}; +use leo_lang::{cli::*, commands::*, errors::CLIError, logger, updater::Updater}; use clap::{App, AppSettings, Arg}; #[cfg_attr(tarpaulin, skip)] fn main() -> Result<(), CLIError> { - let arguments = App::new("leo") + let app = App::new("leo") .version(include_str!("./leo-version")) .about("Leo compiler and package manager") .author("The Aleo Team ") @@ -28,7 +28,6 @@ fn main() -> Result<(), CLIError> { AppSettings::ColoredHelp, AppSettings::DisableHelpSubcommand, AppSettings::DisableVersion, - AppSettings::SubcommandRequiredElseHelp, ]) .args(&[Arg::with_name("debug") .short("d") @@ -53,18 +52,10 @@ fn main() -> Result<(), CLIError> { LintCommand::new().display_order(14), UpdateCommand::new().display_order(15), ]) - .set_term_width(0) - .get_matches(); + .set_term_width(0); - let config = Config::read_config()?; - - if config.auto_update && arguments.subcommand().0 != "update" { - if let Ok(status) = UpdateCommand::update_to_latest_release(false) { - if status.updated() { - tracing::info!("Leo has successfully updated to version: {}", status.version()); - } - } - } + let mut help = app.clone(); + let arguments = app.get_matches(); match arguments.subcommand() { ("new", Some(arguments)) => NewCommand::process(arguments), @@ -83,6 +74,17 @@ fn main() -> Result<(), CLIError> { ("clean", Some(arguments)) => CleanCommand::process(arguments), ("lint", Some(arguments)) => LintCommand::process(arguments), ("update", Some(arguments)) => UpdateCommand::process(arguments), - _ => unreachable!(), + _ => { + // Set logging environment + match arguments.is_present("debug") { + true => logger::init_logger("leo", 2), + false => logger::init_logger("leo", 1), + } + + Updater::print_cli(); + + help.print_help()?; + Ok(()) + } } }