mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-12-26 11:45:00 +03:00
Integrate leo updater to cli
This commit is contained in:
parent
a2a0eca892
commit
3df5405483
@ -14,7 +14,7 @@
|
|||||||
// 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_types::*, errors::CLIError, logger};
|
use crate::{cli_types::*, errors::CLIError, logger, updater::Updater};
|
||||||
|
|
||||||
use clap::{App, AppSettings, Arg, ArgMatches, SubCommand};
|
use clap::{App, AppSettings, Arg, ArgMatches, SubCommand};
|
||||||
|
|
||||||
@ -90,6 +90,10 @@ pub trait CLI {
|
|||||||
false => logger::init_logger("leo", 1),
|
false => logger::init_logger("leo", 1),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if arguments.subcommand().0 != "update" {
|
||||||
|
Updater::print_cli();
|
||||||
|
}
|
||||||
|
|
||||||
let options = Self::parse(arguments)?;
|
let options = Self::parse(arguments)?;
|
||||||
let _output = Self::output(options)?;
|
let _output = Self::output(options)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -56,7 +56,7 @@ pub struct Config {
|
|||||||
|
|
||||||
impl Default for Config {
|
impl Default for Config {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self { auto_update: true }
|
Self { auto_update: false }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
32
leo/main.rs
32
leo/main.rs
@ -14,13 +14,13 @@
|
|||||||
// 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 leo_lang::{cli::*, commands::*, config::Config, errors::CLIError};
|
use leo_lang::{cli::*, commands::*, errors::CLIError, logger, updater::Updater};
|
||||||
|
|
||||||
use clap::{App, AppSettings, Arg};
|
use clap::{App, AppSettings, Arg};
|
||||||
|
|
||||||
#[cfg_attr(tarpaulin, skip)]
|
#[cfg_attr(tarpaulin, skip)]
|
||||||
fn main() -> Result<(), CLIError> {
|
fn main() -> Result<(), CLIError> {
|
||||||
let arguments = App::new("leo")
|
let app = App::new("leo")
|
||||||
.version(include_str!("./leo-version"))
|
.version(include_str!("./leo-version"))
|
||||||
.about("Leo compiler and package manager")
|
.about("Leo compiler and package manager")
|
||||||
.author("The Aleo Team <hello@aleo.org>")
|
.author("The Aleo Team <hello@aleo.org>")
|
||||||
@ -28,7 +28,6 @@ fn main() -> Result<(), CLIError> {
|
|||||||
AppSettings::ColoredHelp,
|
AppSettings::ColoredHelp,
|
||||||
AppSettings::DisableHelpSubcommand,
|
AppSettings::DisableHelpSubcommand,
|
||||||
AppSettings::DisableVersion,
|
AppSettings::DisableVersion,
|
||||||
AppSettings::SubcommandRequiredElseHelp,
|
|
||||||
])
|
])
|
||||||
.args(&[Arg::with_name("debug")
|
.args(&[Arg::with_name("debug")
|
||||||
.short("d")
|
.short("d")
|
||||||
@ -53,18 +52,10 @@ fn main() -> Result<(), CLIError> {
|
|||||||
LintCommand::new().display_order(14),
|
LintCommand::new().display_order(14),
|
||||||
UpdateCommand::new().display_order(15),
|
UpdateCommand::new().display_order(15),
|
||||||
])
|
])
|
||||||
.set_term_width(0)
|
.set_term_width(0);
|
||||||
.get_matches();
|
|
||||||
|
|
||||||
let config = Config::read_config()?;
|
let mut help = app.clone();
|
||||||
|
let arguments = app.get_matches();
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
match arguments.subcommand() {
|
match arguments.subcommand() {
|
||||||
("new", Some(arguments)) => NewCommand::process(arguments),
|
("new", Some(arguments)) => NewCommand::process(arguments),
|
||||||
@ -83,6 +74,17 @@ fn main() -> Result<(), CLIError> {
|
|||||||
("clean", Some(arguments)) => CleanCommand::process(arguments),
|
("clean", Some(arguments)) => CleanCommand::process(arguments),
|
||||||
("lint", Some(arguments)) => LintCommand::process(arguments),
|
("lint", Some(arguments)) => LintCommand::process(arguments),
|
||||||
("update", Some(arguments)) => UpdateCommand::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(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user