Skip to content
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

Merged
merged 5 commits into from
Feb 11, 2021

Conversation

damirka
Copy link
Contributor

@damirka damirka commented Feb 8, 2021

This PR is a reopened #618 to support CI secrets in login workflow

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

Test Plan

Includes integration tests for leo binary and patches to GitHub Actions workflows.

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
@damirka damirka added feature A new feature. refactor Refactor or cleanup. ci labels Feb 8, 2021
@damirka damirka self-assigned this Feb 8, 2021
@damirka damirka mentioned this pull request Feb 8, 2021
12 tasks
@codecov
Copy link

codecov bot commented Feb 8, 2021

Codecov Report

Merging #632 (cb050aa) into master (1898cc6) will decrease coverage by 0.71%.
The diff coverage is 80.57%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
leo/lib.rs 100.00% <ø> (ø)
leo/main.rs 100.00% <ø> (ø)
leo/synthesizer/serialized_circuit.rs 59.74% <ø> (ø)
leo/synthesizer/serialized_field.rs 0.00% <ø> (ø)
leo/synthesizer/serialized_index.rs 0.00% <ø> (ø)
leo/commands/package/login.rs 52.94% <52.94%> (ø)
leo/api.rs 62.16% <62.16%> (ø)
leo/commands/package/logout.rs 56.25% <66.66%> (ø)
leo/commands/update.rs 77.77% <75.00%> (ø)
leo/commands/setup.rs 52.94% <78.57%> (ø)
... and 95 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1898cc6...2c5c2eb. Read the comment docs.

leo/commands/prove.rs Outdated Show resolved Hide resolved
leo/commands/setup.rs Outdated Show resolved Hide resolved
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> {
Copy link
Member

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)?

Copy link
Contributor Author

@damirka damirka Feb 9, 2021

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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. nit: please rename cmd to command
  2. question: if we're telling structopt to simply flatten the command, is there a reason we need to initialize the inner cmd?

Copy link
Contributor Author

@damirka damirka Feb 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Done.
  2. 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;
Copy link
Member

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

Copy link
Contributor Author

@damirka damirka Feb 9, 2021

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.

use crate::{cli::*, cli_types::*, commands::ProveCommand, errors::CLIError};
use crate::{commands::Command, context::Context};

use anyhow::Result;
Copy link
Member

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 leo_package::{outputs::ProofFile, root::Manifest};
use super::setup::Setup;
use crate::{commands::Command, context::Context};
use anyhow::Result;
Copy link
Member

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};
Copy link
Member

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;
Copy link
Member

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

Comment on lines 17 to 30
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;
Copy link
Member

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;
Copy link
Member

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

Comment on lines 47 to 61
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;
Copy link
Member

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;
Copy link
Member

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;
Copy link
Member

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

errors::{CLIError, InitError},
};
use crate::{commands::Command, context::Context};
use anyhow::{anyhow, Result};
Copy link
Member

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;
Copy link
Member

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 crate::{commands::Command, context::Context};
use anyhow::Result;
Copy link
Member

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
Comment on lines 17 to 24
use serde::Serialize;

use anyhow::{anyhow, Error, Result};
use reqwest::{
blocking::{Client, Response},
Method,
StatusCode,
};
Copy link
Member

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

Copy link
Contributor Author

@damirka damirka Feb 9, 2021

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
@damirka damirka requested a review from howardwu February 9, 2021 16:58
- leo new/init now don't have --lib flag
- imports sorted
- command descriptions match old ones 1-to-1
leo/main.rs Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A new feature. refactor Refactor or cleanup.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants