imports sorting, --lib flag removed

- leo new/init now don't have --lib flag
- imports sorted
- command descriptions match old ones 1-to-1
This commit is contained in:
damirka 2021-02-10 19:18:04 +03:00
parent deb830ce65
commit 7867ab9d54
21 changed files with 99 additions and 120 deletions

View File

@ -14,26 +14,25 @@
// 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 std::convert::TryFrom;
use anyhow::Result;
use crate::{
commands::Command,
context::Context,
synthesizer::{CircuitSynthesizer, SerializedCircuit},
};
use leo_compiler::{compiler::Compiler, group::targets::edwards_bls12::EdwardsGroupType};
use leo_package::{
inputs::*,
outputs::{ChecksumFile, CircuitFile, OutputsDirectory, OUTPUTS_DIRECTORY_NAME},
source::{LibraryFile, MainFile, LIBRARY_FILENAME, MAIN_FILENAME, SOURCE_DIRECTORY_NAME},
};
use anyhow::Result;
use snarkvm_curves::{bls12_377::Bls12_377, edwards_bls12::Fq};
use snarkvm_models::gadgets::r1cs::ConstraintSystem;
use std::convert::TryFrom;
use structopt::StructOpt;
use tracing::span::Span;
use crate::{
commands::Command,
context::Context,
synthesizer::{CircuitSynthesizer, SerializedCircuit},
};
/// Compile and build program command
#[derive(StructOpt, Debug, Default)]
#[structopt(setting = structopt::clap::AppSettings::ColoredHelp)]

View File

@ -14,14 +14,14 @@
// 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 anyhow::Result;
use crate::{commands::Command, context::Context};
use leo_compiler::OutputFile;
use leo_package::outputs::{ChecksumFile, CircuitFile, ProofFile, ProvingKeyFile, VerificationKeyFile};
use anyhow::Result;
use structopt::StructOpt;
use tracing::span::Span;
use crate::{commands::Command, context::Context};
/// Clean outputs folder command
#[derive(StructOpt, Debug, Default)]
#[structopt(setting = structopt::clap::AppSettings::ColoredHelp)]

View File

@ -14,12 +14,12 @@
// 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 crate::{commands::Command, context::Context};
use anyhow::Result;
use structopt::StructOpt;
use tracing::span::Span;
use crate::{commands::Command, context::Context};
/// Deploy Leo program to the network
#[derive(StructOpt, Debug, Default)]
#[structopt(setting = structopt::clap::AppSettings::ColoredHelp)]

View File

@ -14,26 +14,22 @@
// 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 std::env::current_dir;
use crate::{commands::Command, context::Context};
use leo_package::LeoPackage;
use anyhow::{anyhow, Result};
use leo_package::LeoPackage;
use std::env::current_dir;
use structopt::StructOpt;
use tracing::span::Span;
use crate::{commands::Command, context::Context};
/// Init Leo project command within current directory
#[derive(StructOpt, Debug)]
#[derive(StructOpt, Debug, Default)]
#[structopt(setting = structopt::clap::AppSettings::ColoredHelp)]
pub struct Init {
#[structopt(help = "Init as a library (containing lib.leo)", long = "lib", short = "l")]
is_lib: Option<bool>,
}
pub struct Init {}
impl Init {
pub fn new(is_lib: Option<bool>) -> Init {
Init { is_lib }
pub fn new() -> Init {
Init {}
}
}
@ -61,7 +57,7 @@ impl Command for Init {
return Err(anyhow!("Directory does not exist"));
}
LeoPackage::initialize(&package_name, self.is_lib.unwrap_or(false), &path)?;
LeoPackage::initialize(&package_name, false, &path)?;
Ok(())
}

View File

@ -14,12 +14,12 @@
// 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 crate::{commands::Command, context::Context};
use anyhow::Result;
use structopt::StructOpt;
use tracing::span::Span;
use crate::{commands::Command, context::Context};
/// Lint Leo code command
#[derive(StructOpt, Debug, Default)]
#[structopt(setting = structopt::clap::AppSettings::ColoredHelp)]

View File

@ -14,13 +14,12 @@
// 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 std::time::Instant;
use crate::context::{get_context, Context};
use anyhow::Result;
use std::time::Instant;
use tracing::span::Span;
use crate::context::{get_context, Context};
// local program commands
pub mod build;
pub use build::Build;

View File

@ -14,29 +14,25 @@
// 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 std::{env::current_dir, fs};
use crate::{commands::Command, context::Context};
use leo_package::LeoPackage;
use anyhow::{anyhow, Result};
use leo_package::LeoPackage;
use std::{env::current_dir, fs};
use structopt::StructOpt;
use tracing::span::Span;
use crate::{commands::Command, context::Context};
/// Create new Leo project
#[derive(StructOpt, Debug)]
#[structopt(setting = structopt::clap::AppSettings::ColoredHelp)]
pub struct New {
#[structopt(name = "NAME", help = "Set package name")]
name: String,
#[structopt(help = "Init as a library (containing lib.leo)", long = "lib", short = "l")]
is_lib: bool,
}
impl New {
pub fn new(name: String, is_lib: bool) -> New {
New { name, is_lib }
pub fn new(name: String) -> New {
New { name }
}
}
@ -67,7 +63,7 @@ impl Command for New {
// Create the package directory
fs::create_dir_all(&path).map_err(|err| anyhow!("Could not create directory {}", err))?;
LeoPackage::initialize(&package_name, self.is_lib, &path)?;
LeoPackage::initialize(&package_name, false, &path)?;
Ok(())
}

View File

@ -14,18 +14,17 @@
// 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 crate::{api::Fetch, commands::Command, context::Context};
use leo_package::imports::{ImportsDirectory, IMPORTS_DIRECTORY_NAME};
use anyhow::{anyhow, Result};
use std::{
fs::{create_dir_all, File},
io::{Read, Write},
};
use anyhow::{anyhow, Result};
use leo_package::imports::{ImportsDirectory, IMPORTS_DIRECTORY_NAME};
use structopt::StructOpt;
use tracing::Span;
use crate::{api::Fetch, commands::Command, context::Context};
/// Add package from Aleo Package Manager
#[derive(StructOpt, Debug)]
#[structopt(setting = structopt::clap::AppSettings::ColoredHelp)]

View File

@ -14,12 +14,6 @@
// 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 std::collections::HashMap;
use anyhow::{anyhow, Result};
use structopt::StructOpt;
use tracing::Span;
use crate::{
api::{Login as LoginRoute, Profile as ProfileRoute},
commands::Command,
@ -27,6 +21,11 @@ use crate::{
context::Context,
};
use anyhow::{anyhow, Result};
use std::collections::HashMap;
use structopt::StructOpt;
use tracing::Span;
pub const LOGIN_URL: &str = "v1/account/authenticate";
pub const PROFILE_URL: &str = "v1/account/my_profile";

View File

@ -14,14 +14,13 @@
// 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 std::io::ErrorKind;
use crate::{commands::Command, config::remove_token, context::Context};
use anyhow::Result;
use std::io::ErrorKind;
use structopt::StructOpt;
use tracing::Span;
use crate::{commands::Command, config::remove_token, context::Context};
/// Remove credentials for Aleo PM from .leo directory
#[derive(StructOpt, Debug, Default)]
#[structopt(setting = structopt::clap::AppSettings::ColoredHelp)]

View File

@ -14,8 +14,14 @@
// 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 anyhow::{anyhow, Result};
use super::build::Build;
use crate::{
commands::Command,
context::{Context, PACKAGE_MANAGER_URL},
};
use leo_package::{outputs::OutputsDirectory, root::ZipFile};
use anyhow::{anyhow, Result};
use reqwest::{
blocking::{multipart::Form, Client},
header::{HeaderMap, HeaderValue},
@ -23,12 +29,6 @@ use reqwest::{
use serde::Deserialize;
use structopt::StructOpt;
use super::build::Build;
use crate::{
commands::Command,
context::{Context, PACKAGE_MANAGER_URL},
};
pub const PUBLISH_URL: &str = "v1/package/publish";
#[derive(Deserialize)]

View File

@ -14,13 +14,13 @@
// 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 anyhow::Result;
use crate::{commands::Command, context::Context};
use leo_package::LeoPackage;
use anyhow::Result;
use structopt::StructOpt;
use tracing::span::Span;
use crate::{commands::Command, context::Context};
/// Remove imported package
#[derive(StructOpt, Debug, Default)]
#[structopt(setting = structopt::clap::AppSettings::ColoredHelp)]

View File

@ -14,19 +14,19 @@
// 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 anyhow::Result;
use super::setup::Setup;
use crate::{commands::Command, context::Context};
use leo_package::outputs::ProofFile;
use rand::thread_rng;
use snarkvm_algorithms::snark::groth16::{Groth16, PreparedVerifyingKey, Proof};
use snarkvm_curves::bls12_377::{Bls12_377, Fr};
use snarkvm_models::algorithms::SNARK;
use snarkvm_utilities::bytes::ToBytes;
use anyhow::Result;
use rand::thread_rng;
use structopt::StructOpt;
use tracing::span::Span;
use super::setup::Setup;
use crate::{commands::Command, context::Context};
/// Run the program and produce a proof
#[derive(StructOpt, Debug, Default)]
#[structopt(setting = structopt::clap::AppSettings::ColoredHelp)]

View File

@ -14,17 +14,17 @@
// 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 anyhow::Result;
use super::prove::Prove;
use crate::{commands::Command, context::Context};
use leo_compiler::{compiler::Compiler, group::targets::edwards_bls12::EdwardsGroupType};
use anyhow::Result;
use snarkvm_algorithms::snark::groth16::Groth16;
use snarkvm_curves::bls12_377::{Bls12_377, Fr};
use snarkvm_models::algorithms::SNARK;
use structopt::StructOpt;
use tracing::span::Span;
use super::prove::Prove;
use crate::{commands::Command, context::Context};
/// Build, Prove and Run Leo program with inputs
#[derive(StructOpt, Debug, Default)]
#[structopt(setting = structopt::clap::AppSettings::ColoredHelp)]

View File

@ -14,12 +14,15 @@
// 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 anyhow::{anyhow, Result};
use super::build::Build;
use crate::{commands::Command, context::Context};
use leo_compiler::{compiler::Compiler, group::targets::edwards_bls12::EdwardsGroupType};
use leo_package::{
outputs::{ProvingKeyFile, VerificationKeyFile},
source::{MAIN_FILENAME, SOURCE_DIRECTORY_NAME},
};
use anyhow::{anyhow, Result};
use rand::thread_rng;
use snarkvm_algorithms::snark::groth16::{Groth16, Parameters, PreparedVerifyingKey, VerifyingKey};
use snarkvm_curves::bls12_377::{Bls12_377, Fr};
@ -27,10 +30,7 @@ use snarkvm_models::algorithms::snark::SNARK;
use structopt::StructOpt;
use tracing::span::Span;
use super::build::Build;
use crate::{commands::Command, context::Context};
/// Run a program setup
/// Executes the setup command for a Leo program
#[derive(StructOpt, Debug, Default)]
#[structopt(setting = structopt::clap::AppSettings::ColoredHelp)]
pub struct Setup {
@ -78,7 +78,7 @@ impl Command for Setup {
// Run the program setup operation
let rng = &mut thread_rng();
let (proving_key, prepared_verifying_key) =
Groth16::<Bls12_377, Compiler<Fr, _>, Vec<Fr>>::setup(&program, rng).unwrap();
Groth16::<Bls12_377, Compiler<Fr, _>, Vec<Fr>>::setup(&program, rng)?;
// TODO (howardwu): Convert parameters to a 'proving key' struct for serialization.
// Write the proving key file to the output directory

View File

@ -14,21 +14,20 @@
// 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 std::{convert::TryFrom, path::PathBuf, time::Instant};
use anyhow::{anyhow, Result};
use crate::{commands::Command, context::Context};
use leo_compiler::{compiler::Compiler, group::targets::edwards_bls12::EdwardsGroupType};
use leo_package::{
inputs::*,
outputs::{OutputsDirectory, OUTPUTS_DIRECTORY_NAME},
source::{LibraryFile, MainFile, LIBRARY_FILENAME, MAIN_FILENAME, SOURCE_DIRECTORY_NAME},
source::{MainFile, MAIN_FILENAME, SOURCE_DIRECTORY_NAME},
};
use anyhow::{anyhow, Result};
use snarkvm_curves::edwards_bls12::Fq;
use std::{convert::TryFrom, path::PathBuf, time::Instant};
use structopt::StructOpt;
use tracing::span::Span;
use crate::{commands::Command, context::Context};
/// Build program and run tests command
#[derive(StructOpt, Debug, Default)]
#[structopt(setting = structopt::clap::AppSettings::ColoredHelp)]
@ -78,14 +77,7 @@ impl Command for Test {
file_path.push(MAIN_FILENAME);
to_test.push(file_path);
// if main file is not present and no arguments - try library
} else if LibraryFile::exists_at(&package_path) {
let mut file_path = package_path.clone();
file_path.push(SOURCE_DIRECTORY_NAME);
file_path.push(LIBRARY_FILENAME);
to_test.push(file_path);
// nothing found - skip
// when no main file and no files marked - error
} else {
return Err(anyhow!(
"Program file does not exist {}",

View File

@ -14,12 +14,12 @@
// 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 crate::{commands::Command, config::Config, context::Context, updater::Updater};
use anyhow::{anyhow, Result};
use structopt::StructOpt;
use tracing::span::Span;
use crate::{commands::Command, config::Config, context::Context, updater::Updater};
/// Setting for automatic updates of Leo
#[derive(Debug, StructOpt, PartialEq)]
pub enum Sub {

View File

@ -14,6 +14,9 @@
// 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 super::build::Build;
use crate::{commands::Command, context::Context};
use std::{sync::mpsc::channel, time::Duration};
use anyhow::{anyhow, Result};
@ -21,9 +24,6 @@ use notify::{watcher, DebouncedEvent, RecursiveMode, Watcher};
use structopt::StructOpt;
use tracing::span::Span;
use super::build::Build;
use crate::{commands::Command, context::Context};
const LEO_SOURCE_DIR: &str = "src/";
/// Watch file changes in src/ directory and run Build Command

View File

@ -14,12 +14,11 @@
// 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 std::{convert::TryFrom, env::current_dir, path::PathBuf};
use anyhow::Result;
use crate::{api::Api, config};
use leo_package::root::Manifest;
use crate::{api::Api, config};
use anyhow::Result;
use std::{convert::TryFrom, env::current_dir, path::PathBuf};
pub const PACKAGE_MANAGER_URL: &str = "https://api.aleo.pm/";

View File

@ -22,9 +22,6 @@ pub mod logger;
pub mod synthesizer;
pub mod updater;
use std::process::exit;
use anyhow::Error;
use commands::{
package::{Add, Login, Logout, Publish, Remove},
Build,
@ -41,6 +38,9 @@ use commands::{
Update,
Watch,
};
use anyhow::Error;
use std::process::exit;
use structopt::{clap::AppSettings, StructOpt};
/// CLI Arguments entry point - includes global parameters and subcommands
@ -61,19 +61,19 @@ struct Opt {
#[derive(StructOpt, Debug)]
#[structopt(setting = AppSettings::ColoredHelp)]
enum CommandOpts {
#[structopt(about = "Init new Leo project command in current directory")]
#[structopt(about = "Create a new Leo package in an existing directory")]
Init {
#[structopt(flatten)]
command: Init,
},
#[structopt(about = "Create new Leo project in new directory")]
#[structopt(about = "Create a new Leo package in a new directory")]
New {
#[structopt(flatten)]
command: New,
},
#[structopt(about = "Compile current package as a program")]
#[structopt(about = "Compile the current package as a program")]
Build {
#[structopt(flatten)]
command: Build,
@ -97,19 +97,19 @@ enum CommandOpts {
command: Run,
},
#[structopt(about = "Clean current package: remove proof and circuits")]
#[structopt(about = "Clean the output directory")]
Clean {
#[structopt(flatten)]
command: Clean,
},
#[structopt(about = "Watch for changes of Leo source files and run build")]
#[structopt(about = "Watch for changes of Leo source files")]
Watch {
#[structopt(flatten)]
command: Watch,
},
#[structopt(about = "Watch for changes of Leo source files and run build")]
#[structopt(about = "Update Leo to the latest version")]
Update {
#[structopt(flatten)]
command: Update,
@ -121,37 +121,37 @@ enum CommandOpts {
command: Test,
},
#[structopt(about = "Import package from Aleo PM")]
#[structopt(about = "Install a package from the Aleo Package Manager")]
Add {
#[structopt(flatten)]
command: Add,
},
#[structopt(about = "Login to the package manager and store credentials")]
#[structopt(about = "Login to the Aleo Package Manager")]
Login {
#[structopt(flatten)]
command: Login,
},
#[structopt(about = "Logout - remove local credentials")]
#[structopt(about = "Logout of the package manager and removes credentials")]
Logout {
#[structopt(flatten)]
command: Logout,
},
#[structopt(about = "Publish package")]
#[structopt(about = "Publish the current package to the Aleo Package Manager")]
Publish {
#[structopt(flatten)]
command: Publish,
},
#[structopt(about = "Remove imported package")]
#[structopt(about = "Uninstall a package from the current package")]
Remove {
#[structopt(flatten)]
command: Remove,
},
#[structopt(about = "Lint package code (not implemented)")]
#[structopt(about = "Lints the Leo files in the package (*)")]
Lint {
#[structopt(flatten)]
command: Lint,

View File

@ -13,12 +13,13 @@
// 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 crate::config::Config;
use anyhow::{anyhow, Result};
use colored::Colorize;
use self_update::{backends::github, version::bump_is_greater, Status};
use crate::config::Config;
pub struct Updater;
// TODO Add logic for users to easily select release versions.