Fix styling and naming

This commit is contained in:
collin 2020-08-21 19:53:56 -07:00
parent 55fdb24bfb
commit 5ab4d62a2b
6 changed files with 50 additions and 35 deletions

View File

@ -21,12 +21,7 @@
// leo add -a author -p package_name // leo add -a author -p package_name
// //
use crate::{ use crate::{cli::CLI, cli_types::*, config::*, errors::AddError::*};
cli::CLI,
cli_types::*,
config::*,
errors::{AddError::*, CLIError::AddError},
};
use leo_package::{ use leo_package::{
imports::{ImportsDirectory, IMPORTS_DIRECTORY_NAME}, imports::{ImportsDirectory, IMPORTS_DIRECTORY_NAME},
root::Manifest, root::Manifest,
@ -90,7 +85,7 @@ impl CLI for AddCommand {
fn output(options: Self::Options) -> Result<Self::Output, crate::errors::CLIError> { fn output(options: Self::Options) -> Result<Self::Output, crate::errors::CLIError> {
// Begin "Adding" context for console logging // Begin "Adding" context for console logging
let span = tracing::span!(tracing::Level::INFO, "Adding"); let span = tracing::span!(tracing::Level::INFO, "Adding");
let enter = span.enter(); let _enter = span.enter();
let token = read_token()?; let token = read_token()?;
@ -115,13 +110,11 @@ impl CLI for AddCommand {
Ok(response) => (response, package_name), Ok(response) => (response, package_name),
//Cannot connect to the server //Cannot connect to the server
Err(_error) => { Err(_error) => {
return Err(AddError(ConnectionUnavailable( return Err(ConnectionUnavailable("Could not connect to the package manager".into()).into());
"Could not connect to the package manager".into(),
)));
} }
} }
} }
_ => return Err(AddError(MissingAuthorOrPackageName)), _ => return Err(MissingAuthorOrPackageName.into()),
}; };
let mut path = current_dir()?; let mut path = current_dir()?;
@ -135,13 +128,13 @@ impl CLI for AddCommand {
let mut zip_arhive = match zip::ZipArchive::new(reader) { let mut zip_arhive = match zip::ZipArchive::new(reader) {
Ok(zip) => zip, Ok(zip) => zip,
Err(error) => return Err(AddError(ZipError(error.to_string().into()))), Err(error) => return Err(ZipError(error.to_string().into()).into()),
}; };
for i in 0..zip_arhive.len() { for i in 0..zip_arhive.len() {
let file = match zip_arhive.by_index(i) { let file = match zip_arhive.by_index(i) {
Ok(file) => file, Ok(file) => file,
Err(error) => return Err(AddError(ZipError(error.to_string().into()))), Err(error) => return Err(ZipError(error.to_string().into()).into()),
}; };
let file_name = file.name(); let file_name = file.name();
@ -160,7 +153,7 @@ impl CLI for AddCommand {
} }
} }
tracing::info!("Successfully added a package"); tracing::info!("Successfully added a package\n");
Ok(()) Ok(())
} }
} }

View File

@ -117,6 +117,8 @@ impl CLI for InitCommand {
} }
} }
tracing::info!("Successfully initialized package \"{}\"\n", package_name);
Ok(()) Ok(())
} }
} }

View File

@ -116,6 +116,8 @@ impl CLI for NewCommand {
MainFile::new(&package_name).write_to(&path)?; MainFile::new(&package_name).write_to(&path)?;
} }
tracing::info!("Successfully initialized package \"{}\"\n", package_name);
Ok(()) Ok(())
} }
} }

View File

@ -49,7 +49,9 @@ impl CLI for RunCommand {
// Begin "Verifying" context for console logging // Begin "Verifying" context for console logging
let span = tracing::span!(tracing::Level::INFO, "Verifying"); let span = tracing::span!(tracing::Level::INFO, "Verifying");
let _enter = span.enter(); let enter = span.enter();
tracing::info!("Starting...");
let mut verifying = Duration::new(0, 0); let mut verifying = Duration::new(0, 0);
@ -64,9 +66,15 @@ impl CLI for RunCommand {
verifying += start.elapsed(); verifying += start.elapsed();
println!(" Verifier time : {:?} milliseconds", verifying.as_millis()); tracing::info!("Verifier completed in {:?} milliseconds", verifying.as_millis());
println!(" Verifier output : {}", is_success);
println!(" "); // Drop "Verifying" context for console logging
drop(enter);
// Begin "Finished" context for console logging
tracing::span!(tracing::Level::INFO, "Finished").in_scope(|| {
tracing::info!("Verifier output : \"{}\"\n", is_success);
});
Ok(()) Ok(())
} }

View File

@ -105,26 +105,31 @@ impl CLI for TestCommand {
let temporary_program = program.clone(); let temporary_program = program.clone();
let (passed, failed) = temporary_program.compile_test_constraints(pairs)?; let (passed, failed) = temporary_program.compile_test_constraints(pairs)?;
// Set the result of the test command to PASSED if no tests failed.
let result = if failed == 0 {
"PASSED".to_owned()
} else {
"FAILED".to_owned()
};
// Drop "Test" context for console logging // Drop "Test" context for console logging
drop(enter); drop(enter);
// Begin "Finished" context for console logging // Set the result of the test command to passed if no tests failed.
tracing::span!(tracing::Level::INFO, "Finished").in_scope(|| { if failed == 0 {
tracing::info!( // Begin "Finished" context for console logging
"result: {} in {} milliseconds. {} passed; {} failed;\n", tracing::span!(tracing::Level::INFO, "Finished").in_scope(|| {
result, tracing::info!(
start.elapsed().as_millis(), "Tests passed in {} milliseconds. {} passed; {} failed;\n",
passed, start.elapsed().as_millis(),
failed passed,
); failed
}); );
});
} else {
// Begin "Finished" context for console logging
tracing::span!(tracing::Level::ERROR, "Finished").in_scope(|| {
tracing::error!(
"Tests failed in {} milliseconds. {} passed; {} failed;\n",
start.elapsed().as_millis(),
passed,
failed
);
});
};
Ok(()) Ok(())
} }

View File

@ -15,6 +15,7 @@
// 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::errors::*; use crate::errors::*;
use leo_compiler::errors::OutputFileError;
use leo_package::errors::*; use leo_package::errors::*;
#[derive(Debug, Error)] #[derive(Debug, Error)]
@ -67,6 +68,9 @@ pub enum CLIError {
#[error("{}", _0)] #[error("{}", _0)]
NewError(NewError), NewError(NewError),
#[error("{}", _0)]
OutputFileError(OutputFileError),
#[error("{}", _0)] #[error("{}", _0)]
OutputsDirectoryError(OutputsDirectoryError), OutputsDirectoryError(OutputsDirectoryError),
@ -134,6 +138,7 @@ impl_cli_error!(
MainFileError, MainFileError,
ManifestError, ManifestError,
NewError, NewError,
OutputFileError,
OutputsDirectoryError, OutputsDirectoryError,
ProofFileError, ProofFileError,
ProvingKeyFileError, ProvingKeyFileError,