mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-09-11 13:56:58 +03:00
implement binary auto update
This commit is contained in:
parent
d6b0edbd83
commit
45eb0b5e38
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -2202,6 +2202,7 @@ dependencies = [
|
||||
"semver",
|
||||
"serde_json",
|
||||
"tempfile",
|
||||
"zip",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -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" }
|
||||
|
@ -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);
|
||||
|
@ -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),
|
||||
}
|
||||
|
14
leo/main.rs
14
leo/main.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 <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),
|
||||
|
Loading…
Reference in New Issue
Block a user