-
Notifications
You must be signed in to change notification settings - Fork 660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CLI] Leo CLI is now on StructOpt and Anyhow (reopened) #632
Conversation
Features: - introduces new Command and Route traits for Leo commands and Aleo PM API - most of the CLI code replace with higher-level abstraction - StructOpt - anyhow used for error handling, no more custom error classes - improves API - now every status code has its business logic - adds global flags (e.g. --quiet to suppress output) - error messages improved for convenience and better user experience Closes: - #604 - #599 - #584 - #277 - #376
Codecov Report
@@ Coverage Diff @@
## master #632 +/- ##
==========================================
- Coverage 75.69% 74.97% -0.72%
==========================================
Files 518 549 +31
Lines 16135 17258 +1123
==========================================
+ Hits 12214 12940 +726
- Misses 3921 4318 +397
Continue to review full report at Codecov.
|
leo/updater.rs
Outdated
@@ -27,7 +28,7 @@ impl Updater { | |||
const LEO_REPO_OWNER: &'static str = "AleoHQ"; | |||
|
|||
/// Show all available releases for `leo`. | |||
pub fn show_available_releases() -> Result<(), UpdaterError> { | |||
pub fn show_available_releases() -> Result<(), Error> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this change to anyhow::Error
produce the same UpdaterError
message in the terminal as before (if any)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are the outputs (when no network available):
Current version:
Updating ReqwestError: error sending request for url (https://api.github.com/repos/AleoHQ/leo/releases/latest): error trying to connect: dns error: failed to lookup address information: nodename nor servname provided, or not known
Updating Could not update Leo to the latest version
Updating self_update: ReqwestError: error sending request for url (https://api.github.com/repos/AleoHQ/leo/releases/latest): error trying to connect: dns error: failed to lookup address information: nodename nor servname provided, or not known
This update:
Updating Could not update Leo to the latest version
Updating ReqwestError: error sending request for url (https://api.github.com/repos/AleoHQ/leo/releases/latest): error trying to connect: dns error: failed to lookup address information: nodename nor servname provided, or not known
leo/main.rs
Outdated
#[structopt(about = "Init new Leo project command in current directory")] | ||
Init { | ||
#[structopt(flatten)] | ||
cmd: Init, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- nit: please rename
cmd
tocommand
- question: if we're telling
structopt
to simply flatten the command, is there a reason we need to initialize the innercmd
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Done.
- We need to, yes. Flattening allows using external structs as subcommands + see how this code is called within main function. It also gives an option for grouping if we'll want to.
source::{MAIN_FILENAME, SOURCE_DIRECTORY_NAME}, | ||
}; | ||
|
||
use rand::thread_rng; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: please organize the imports here into two sections - leo specific crates & external crates
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here and below: used rustfmt rule for grouping imports.
leo/commands/run.rs
Outdated
use crate::{cli::*, cli_types::*, commands::ProveCommand, errors::CLIError}; | ||
use crate::{commands::Command, context::Context}; | ||
|
||
use anyhow::Result; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: please organize the imports here into two sections - leo specific crates & external crates
leo/commands/prove.rs
Outdated
use leo_package::{outputs::ProofFile, root::Manifest}; | ||
use super::setup::Setup; | ||
use crate::{commands::Command, context::Context}; | ||
use anyhow::Result; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: please organize the imports here into two sections - leo specific crates & external crates
}; | ||
|
||
use clap::ArgMatches; | ||
use anyhow::{anyhow, Result}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: please organize the imports here into two sections - leo specific crates & external crates
|
||
use crate::{cli::CLI, cli_types::*, config::remove_token, errors::CLIError}; | ||
use crate::config::remove_token; | ||
use anyhow::Result; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: please organize the imports here into two sections - leo specific crates & external crates
leo/commands/package/add.rs
Outdated
use leo_package::imports::{ImportsDirectory, IMPORTS_DIRECTORY_NAME}; | ||
use tracing::Span; | ||
|
||
use std::{ | ||
fs::{create_dir_all, File}, | ||
io::{Read, Write}, | ||
}; | ||
|
||
use crate::{commands::Command, context::Context}; | ||
|
||
use anyhow::{anyhow, Result}; | ||
use structopt::StructOpt; | ||
|
||
use crate::api::Fetch; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: please organize the imports here into two sections - leo specific crates & external crates
|
||
use clap::ArgMatches; | ||
use leo_package::LeoPackage; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: please organize the imports here into two sections - leo specific crates & external crates
leo/commands/mod.rs
Outdated
pub mod watch; | ||
pub use watch::Watch; | ||
|
||
pub mod update; | ||
pub use self::update::*; | ||
pub use update::{Sub as UpdateAutomatic, Update}; | ||
|
||
pub mod watch; | ||
pub use self::watch::*; | ||
// aleo pm related commands | ||
pub mod package; | ||
|
||
// not implemented | ||
pub mod deploy; | ||
pub use deploy::Deploy; | ||
|
||
pub mod lint; | ||
pub use lint::Lint; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: please sort alphabetically
pub mod add; | ||
pub use self::add::*; | ||
use crate::context::{get_context, Context}; | ||
use anyhow::Result; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: please organize the imports here into two sections - leo specific crates & external crates
#[derive(Debug)] | ||
pub struct LintCommand; | ||
use crate::{commands::Command, context::Context}; | ||
use anyhow::Result; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: please organize the imports here into two sections - leo specific crates & external crates
leo/commands/init.rs
Outdated
errors::{CLIError, InitError}, | ||
}; | ||
use crate::{commands::Command, context::Context}; | ||
use anyhow::{anyhow, Result}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: please organize the imports here into two sections - leo specific crates & external crates
#[derive(Debug)] | ||
pub struct DeployCommand; | ||
use crate::{commands::Command, context::Context}; | ||
use anyhow::Result; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: please organize the imports here into two sections - leo specific crates & external crates
leo/commands/clean.rs
Outdated
|
||
use clap::ArgMatches; | ||
use crate::{commands::Command, context::Context}; | ||
use anyhow::Result; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: please organize the imports here into two sections - leo specific crates & external crates
leo/api.rs
Outdated
use serde::Serialize; | ||
|
||
use anyhow::{anyhow, Error, Result}; | ||
use reqwest::{ | ||
blocking::{Client, Response}, | ||
Method, | ||
StatusCode, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: please combine for rustfmt to sort
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't understand this one. What do you mean by combining?
- fixes import ordering (with rule group_imports) - removes explicit 0group from pedersen hash example - updater is now fully-anyhow-ed :) - fixed doc comment in prove command - renamed cmd to command in main
- leo new/init now don't have --lib flag - imports sorted - command descriptions match old ones 1-to-1
Features
Closes
leo test
on a fresh --lib project #376Test Plan
Includes integration tests for leo binary and patches to GitHub Actions workflows.