implement binary auto update

This commit is contained in:
raychu86 2020-08-21 01:49:34 -07:00
parent d6b0edbd83
commit 45eb0b5e38
5 changed files with 32 additions and 7 deletions

1
Cargo.lock generated
View File

@ -2202,6 +2202,7 @@ dependencies = [
"semver",
"serde_json",
"tempfile",
"zip",
]
[[package]]

View File

@ -43,7 +43,7 @@ num-bigint = { version = "0.3" }
rand = { version = "0.7" }
rand_core = { version = "0.5.1" }
reqwest = { version = "0.10.7", features = ["blocking", "json"] }
self_update = { version = "0.19.0" }
self_update = { version = "0.19.0", features = ["archive-zip"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0" }
toml = { version = "0.5" }

View File

@ -16,7 +16,7 @@
use crate::{cli::CLI, cli_types::*};
use self_update::{backends::github, cargo_crate_version};
use self_update::{backends::github, cargo_crate_version, Status};
const LEO_BIN_NAME: &str = "leo";
const LEO_REPO_OWNER: &str = "AleoHQ";
@ -42,7 +42,7 @@ impl UpdateCommand {
}
// Update to the latest release on the current platform
fn update_to_latest_release() -> Result<(), self_update::errors::Error> {
pub fn update_to_latest_release() -> Result<Status, self_update::errors::Error> {
let status = github::Update::configure()
.repo_owner(LEO_REPO_OWNER)
.repo_name(LEO_REPO_NAME)
@ -52,8 +52,7 @@ impl UpdateCommand {
.build()?
.update()?;
log::info!("Leo has successfully updated to {} version", status.version());
Ok(())
Ok(status)
}
}
@ -83,7 +82,14 @@ impl CLI for UpdateCommand {
}
},
(false,) => match UpdateCommand::update_to_latest_release() {
Ok(_) => return Ok(()),
Ok(status) => {
if status.uptodate() {
log::info!("Leo is already on the latest version: {}", status.version());
} else if status.updated() {
log::info!("Leo has successfully updated to version: {}", status.version());
}
return Ok(());
}
Err(e) => {
log::error!("Could not update Leo to the latest version");
log::error!("{}", e);

View File

@ -97,6 +97,12 @@ pub enum CLIError {
#[error("{}", _0)]
TestError(TestError),
#[error("TomlSerError: {0}")]
TomlSerError(#[from] toml::ser::Error),
#[error("TomlDeError: {0}")]
TomlDeError(#[from] toml::de::Error),
#[error("{}", _0)]
VerificationKeyFileError(VerificationKeyFileError),
}

View File

@ -14,7 +14,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 leo::{cli::*, commands::*, errors::CLIError};
use leo::{cli::*, commands::*, config::Config, errors::CLIError};
use clap::{App, AppSettings, Arg};
@ -56,6 +56,18 @@ fn main() -> Result<(), CLIError> {
.set_term_width(0)
.get_matches();
let config = Config::read_config()?;
if config.auto_update {
if let Ok(status) = UpdateCommand::update_to_latest_release() {
if status.updated() {
log::info!("Leo has successfully updated to version: {}", status.version());
}
}
}
// Save the config file
match arguments.subcommand() {
("new", Some(arguments)) => NewCommand::process(arguments),
("init", Some(arguments)) => InitCommand::process(arguments),