mirror of
https://github.com/AleoHQ/leo.git
synced 2025-01-02 06:50:13 +03:00
Adds the command
This commit is contained in:
parent
ffa7c1cce8
commit
c1243a2e74
@ -127,7 +127,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstraintSynthesizer<F> for Compil
|
||||
})?;
|
||||
|
||||
// Write results to file or something
|
||||
// log::info!("{}", result);
|
||||
log::info!("{}", result);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
53
leo/commands/clean.rs
Normal file
53
leo/commands/clean.rs
Normal file
@ -0,0 +1,53 @@
|
||||
use crate::{
|
||||
cli::*,
|
||||
cli_types::*,
|
||||
commands::BuildCommand,
|
||||
errors::CLIError,
|
||||
files::{ChecksumFile, Manifest, ProofFile, ProvingKeyFile, VerificationKeyFile},
|
||||
};
|
||||
|
||||
use clap::ArgMatches;
|
||||
use std::{convert::TryFrom, env::current_dir};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct CleanCommand;
|
||||
|
||||
impl CLI for CleanCommand {
|
||||
type Options = ();
|
||||
type Output = ();
|
||||
|
||||
const ABOUT: AboutType = "Clean the outputs directory";
|
||||
const ARGUMENTS: &'static [ArgumentType] = &[];
|
||||
const FLAGS: &'static [FlagType] = &[];
|
||||
const NAME: NameType = "clean";
|
||||
const OPTIONS: &'static [OptionType] = &[];
|
||||
const SUBCOMMANDS: &'static [SubCommandType] = &[];
|
||||
|
||||
#[cfg_attr(tarpaulin, skip)]
|
||||
fn parse(_arguments: &ArgMatches) -> Result<Self::Options, CLIError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg_attr(tarpaulin, skip)]
|
||||
fn output(options: Self::Options) -> Result<Self::Output, CLIError> {
|
||||
let (_program, _checksum_differs) = BuildCommand::output(options)?;
|
||||
|
||||
// Get the package name
|
||||
let path = current_dir()?;
|
||||
let package_name = Manifest::try_from(&path)?.get_package_name();
|
||||
|
||||
// Remove the checksum from the outputs directory
|
||||
ChecksumFile::new(&package_name).remove(&path)?;
|
||||
|
||||
// Remove the proving key from the outputs directory
|
||||
ProvingKeyFile::new(&package_name).remove(&path)?;
|
||||
|
||||
// Remove the verification key from the outputs directory
|
||||
VerificationKeyFile::new(&package_name).remove(&path)?;
|
||||
|
||||
// Remove the proof from the outputs directory
|
||||
ProofFile::new(&package_name).remove(&path)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
@ -1,6 +1,9 @@
|
||||
pub mod build;
|
||||
pub use self::build::*;
|
||||
|
||||
pub mod clean;
|
||||
pub use self::clean::*;
|
||||
|
||||
pub mod deploy;
|
||||
pub use self::deploy::*;
|
||||
|
||||
|
@ -11,6 +11,9 @@ pub enum ChecksumFileError {
|
||||
#[error("Cannot read from the provided file path - {:?}", _0)]
|
||||
FileReadError(PathBuf),
|
||||
|
||||
#[error("Cannot remove the provided file - {:?}", _0)]
|
||||
FileRemovalError(PathBuf),
|
||||
|
||||
#[error("writing: {}", _0)]
|
||||
Writing(io::Error),
|
||||
}
|
||||
|
@ -11,6 +11,9 @@ pub enum ProofFileError {
|
||||
#[error("Cannot read from the provided file path - {:?}", _0)]
|
||||
FileReadError(PathBuf),
|
||||
|
||||
#[error("Cannot remove the provided file - {:?}", _0)]
|
||||
FileRemovalError(PathBuf),
|
||||
|
||||
#[error("writing: {}", _0)]
|
||||
Writing(io::Error),
|
||||
}
|
||||
|
@ -11,6 +11,9 @@ pub enum ProvingKeyFileError {
|
||||
#[error("Cannot read from the provided file path - {:?}", _0)]
|
||||
FileReadError(PathBuf),
|
||||
|
||||
#[error("Cannot remove the provided file - {:?}", _0)]
|
||||
FileRemovalError(PathBuf),
|
||||
|
||||
#[error("writing: {}", _0)]
|
||||
Writing(io::Error),
|
||||
}
|
||||
|
@ -11,6 +11,9 @@ pub enum VerificationKeyFileError {
|
||||
#[error("Cannot read from the provided file path - {:?}", _0)]
|
||||
FileReadError(PathBuf),
|
||||
|
||||
#[error("Cannot remove the provided file - {:?}", _0)]
|
||||
FileRemovalError(PathBuf),
|
||||
|
||||
#[error("Verification key file was corrupted")]
|
||||
IncorrectVerificationKey,
|
||||
|
||||
|
@ -45,6 +45,18 @@ impl ChecksumFile {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Removes the checksum at the given path if it exists. Returns `true` on success,
|
||||
/// `false` if the file doesn't exist, and `Error` if the file system fails during operation.
|
||||
pub fn remove(&self, path: &PathBuf) -> Result<bool, ChecksumFileError> {
|
||||
let path = self.setup_file_path(path);
|
||||
if !path.exists() {
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
fs::remove_file(&path).map_err(|_| ChecksumFileError::FileRemovalError(path.clone()))?;
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
fn setup_file_path(&self, path: &PathBuf) -> PathBuf {
|
||||
let mut path = path.to_owned();
|
||||
if path.is_dir() {
|
||||
|
@ -48,6 +48,18 @@ impl ProofFile {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Removes the proof at the given path if it exists. Returns `true` on success,
|
||||
/// `false` if the file doesn't exist, and `Error` if the file system fails during operation.
|
||||
pub fn remove(&self, path: &PathBuf) -> Result<bool, ProofFileError> {
|
||||
let path = self.setup_file_path(path);
|
||||
if !path.exists() {
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
fs::remove_file(&path).map_err(|_| ProofFileError::FileRemovalError(path.clone()))?;
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
fn setup_file_path(&self, path: &PathBuf) -> PathBuf {
|
||||
let mut path = path.to_owned();
|
||||
if path.is_dir() {
|
||||
|
@ -45,6 +45,18 @@ impl ProvingKeyFile {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Removes the proving key at the given path if it exists. Returns `true` on success,
|
||||
/// `false` if the file doesn't exist, and `Error` if the file system fails during operation.
|
||||
pub fn remove(&self, path: &PathBuf) -> Result<bool, ProvingKeyFileError> {
|
||||
let path = self.setup_file_path(path);
|
||||
if !path.exists() {
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
fs::remove_file(&path).map_err(|_| ProvingKeyFileError::FileRemovalError(path.clone()))?;
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
fn setup_file_path(&self, path: &PathBuf) -> PathBuf {
|
||||
let mut path = path.to_owned();
|
||||
if path.is_dir() {
|
||||
|
@ -45,6 +45,18 @@ impl VerificationKeyFile {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Removes the verification key at the given path if it exists. Returns `true` on success,
|
||||
/// `false` if the file doesn't exist, and `Error` if the file system fails during operation.
|
||||
pub fn remove(&self, path: &PathBuf) -> Result<bool, VerificationKeyFileError> {
|
||||
let path = self.setup_file_path(path);
|
||||
if !path.exists() {
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
fs::remove_file(&path).map_err(|_| VerificationKeyFileError::FileRemovalError(path.clone()))?;
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
fn setup_file_path(&self, path: &PathBuf) -> PathBuf {
|
||||
let mut path = path.to_owned();
|
||||
if path.is_dir() {
|
||||
|
@ -31,6 +31,7 @@ fn main() -> Result<(), CLIError> {
|
||||
RunCommand::new().display_order(8),
|
||||
PublishCommand::new().display_order(9),
|
||||
DeployCommand::new().display_order(10),
|
||||
CleanCommand::new().display_order(11),
|
||||
])
|
||||
.set_term_width(0)
|
||||
.get_matches();
|
||||
@ -47,6 +48,7 @@ fn main() -> Result<(), CLIError> {
|
||||
("run", Some(arguments)) => RunCommand::process(arguments),
|
||||
("publish", Some(arguments)) => PublishCommand::process(arguments),
|
||||
("deploy", Some(arguments)) => DeployCommand::process(arguments),
|
||||
("clean", Some(arguments)) => CleanCommand::process(arguments),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user