mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-09-11 05:45:30 +03:00
Adds gitignore file, migrates manifest file under files directory
This commit is contained in:
parent
0a34693bae
commit
01ad7a219d
@ -1,7 +1,6 @@
|
||||
use crate::directories::{source::SOURCE_DIRECTORY_NAME, OutputsDirectory};
|
||||
use crate::errors::{BuildError, CLIError};
|
||||
use crate::files::{ChecksumFile, MainFile, MAIN_FILE_NAME};
|
||||
use crate::manifest::Manifest;
|
||||
use crate::files::{ChecksumFile, MainFile, Manifest, MAIN_FILE_NAME};
|
||||
use crate::{cli::*, cli_types::*};
|
||||
use leo_compiler::compiler::Compiler;
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
use crate::directories::{InputsDirectory, SourceDirectory};
|
||||
use crate::errors::{CLIError, InitError};
|
||||
use crate::files::MainFile;
|
||||
use crate::manifest::Manifest;
|
||||
use crate::files::{Gitignore, MainFile, Manifest};
|
||||
use crate::{cli::*, cli_types::*};
|
||||
|
||||
use clap::ArgMatches;
|
||||
@ -54,6 +53,9 @@ impl CLI for InitCommand {
|
||||
// Create the manifest file
|
||||
Manifest::new(&package_name).write_to(&path)?;
|
||||
|
||||
// Create the .gitignore file
|
||||
Gitignore::new().write_to(&path)?;
|
||||
|
||||
// Create the source directory
|
||||
SourceDirectory::create(&path)?;
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
use crate::directories::{InputsDirectory, SourceDirectory};
|
||||
use crate::errors::{CLIError, NewError};
|
||||
use crate::files::MainFile;
|
||||
use crate::manifest::Manifest;
|
||||
use crate::files::{Gitignore, MainFile, Manifest};
|
||||
use crate::{cli::*, cli_types::*};
|
||||
|
||||
use clap::ArgMatches;
|
||||
@ -67,6 +66,9 @@ impl CLI for NewCommand {
|
||||
// Create the manifest file
|
||||
Manifest::new(&package_name).write_to(&path)?;
|
||||
|
||||
// Create the .gitignore file
|
||||
Gitignore::new().write_to(&path)?;
|
||||
|
||||
// Create the source directory
|
||||
SourceDirectory::create(&path)?;
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
use crate::{cli::*, cli_types::*};
|
||||
use crate::commands::SetupCommand;
|
||||
use crate::errors::CLIError;
|
||||
use crate::files::ProofFile;
|
||||
use crate::manifest::Manifest;
|
||||
use crate::files::{Manifest, ProofFile};
|
||||
|
||||
use snarkos_algorithms::snark::{create_random_proof, Proof};
|
||||
use snarkos_curves::bls12_377::Bls12_377;
|
||||
|
@ -1,8 +1,7 @@
|
||||
use crate::{cli::*, cli_types::*};
|
||||
use crate::commands::BuildCommand;
|
||||
use crate::errors::{CLIError, VerificationKeyFileError};
|
||||
use crate::files::{ProvingKeyFile, VerificationKeyFile};
|
||||
use crate::manifest::Manifest;
|
||||
use crate::files::{Manifest, ProvingKeyFile, VerificationKeyFile};
|
||||
use leo_compiler::compiler::Compiler;
|
||||
|
||||
use snarkos_algorithms::snark::{
|
||||
|
@ -11,6 +11,9 @@ pub enum CLIError {
|
||||
#[error("{}", _0)]
|
||||
ChecksumFileError(ChecksumFileError),
|
||||
|
||||
#[error("{}", _0)]
|
||||
GitignoreError(GitignoreError),
|
||||
|
||||
#[error("{}", _0)]
|
||||
InitError(InitError),
|
||||
|
||||
@ -57,6 +60,12 @@ impl From<ChecksumFileError> for CLIError {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<GitignoreError> for CLIError {
|
||||
fn from(error: GitignoreError) -> Self {
|
||||
CLIError::GitignoreError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<InitError> for CLIError {
|
||||
fn from(error: InitError) -> Self {
|
||||
CLIError::InitError(error)
|
||||
|
19
leo/errors/files/gitignore.rs
Normal file
19
leo/errors/files/gitignore.rs
Normal file
@ -0,0 +1,19 @@
|
||||
use std::io;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum GitignoreError {
|
||||
#[error("{}: {}", _0, _1)]
|
||||
Crate(&'static str, String),
|
||||
|
||||
#[error("creating: {}", _0)]
|
||||
Creating(io::Error),
|
||||
|
||||
#[error("writing: {}", _0)]
|
||||
Writing(io::Error),
|
||||
}
|
||||
|
||||
impl From<std::io::Error> for GitignoreError {
|
||||
fn from(error: std::io::Error) -> Self {
|
||||
GitignoreError::Crate("std::io", format!("{}", error))
|
||||
}
|
||||
}
|
@ -1,9 +1,15 @@
|
||||
pub mod checksum;
|
||||
pub use self::checksum::*;
|
||||
|
||||
pub mod gitignore;
|
||||
pub use self::gitignore::*;
|
||||
|
||||
pub mod main;
|
||||
pub use self::main::*;
|
||||
|
||||
pub mod manifest;
|
||||
pub use self::manifest::*;
|
||||
|
||||
pub mod proof;
|
||||
pub use self::proof::*;
|
||||
|
||||
|
@ -9,6 +9,3 @@ pub use self::directory::*;
|
||||
|
||||
pub mod files;
|
||||
pub use self::files::*;
|
||||
|
||||
pub mod manifest;
|
||||
pub use self::manifest::*;
|
||||
|
45
leo/files/gitignore.rs
Normal file
45
leo/files/gitignore.rs
Normal file
@ -0,0 +1,45 @@
|
||||
//! The `.gitignore` file.
|
||||
|
||||
use crate::errors::GitignoreError;
|
||||
|
||||
use serde::Deserialize;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub static GITIGNORE_FILE_NAME: &str = ".gitignore";
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct Gitignore;
|
||||
|
||||
impl Gitignore {
|
||||
pub fn new() -> Self {
|
||||
Self
|
||||
}
|
||||
|
||||
pub fn exists_at(path: &PathBuf) -> bool {
|
||||
let mut path = path.to_owned();
|
||||
if path.is_dir() {
|
||||
path.push(PathBuf::from(GITIGNORE_FILE_NAME));
|
||||
}
|
||||
path.exists()
|
||||
}
|
||||
|
||||
pub fn write_to(self, path: &PathBuf) -> Result<(), GitignoreError> {
|
||||
let mut path = path.to_owned();
|
||||
if path.is_dir() {
|
||||
path.push(PathBuf::from(GITIGNORE_FILE_NAME));
|
||||
}
|
||||
|
||||
let mut file = File::create(&path)?;
|
||||
Ok(file.write_all(self.template().as_bytes())?)
|
||||
}
|
||||
|
||||
fn template(&self) -> String {
|
||||
format!(
|
||||
r#"/output
|
||||
/.leo
|
||||
"#,
|
||||
)
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@ use std::io::Read;
|
||||
use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub static FILE_NAME_DEFAULT: &str = "Leo.toml";
|
||||
pub static MANIFEST_FILE_NAME: &str = "Leo.toml";
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct Package {
|
||||
@ -33,7 +33,7 @@ impl Manifest {
|
||||
pub fn exists_at(path: &PathBuf) -> bool {
|
||||
let mut path = path.to_owned();
|
||||
if path.is_dir() {
|
||||
path.push(PathBuf::from(FILE_NAME_DEFAULT));
|
||||
path.push(PathBuf::from(MANIFEST_FILE_NAME));
|
||||
}
|
||||
path.exists()
|
||||
}
|
||||
@ -45,13 +45,13 @@ impl Manifest {
|
||||
pub fn write_to(self, path: &PathBuf) -> Result<(), ManifestError> {
|
||||
let mut path = path.to_owned();
|
||||
if path.is_dir() {
|
||||
path.push(PathBuf::from(FILE_NAME_DEFAULT));
|
||||
path.push(PathBuf::from(MANIFEST_FILE_NAME));
|
||||
}
|
||||
|
||||
let mut file = File::create(&path)
|
||||
.map_err(|error| ManifestError::Creating(FILE_NAME_DEFAULT, error))?;
|
||||
.map_err(|error| ManifestError::Creating(MANIFEST_FILE_NAME, error))?;
|
||||
file.write_all(self.template().as_bytes())
|
||||
.map_err(|error| ManifestError::Writing(FILE_NAME_DEFAULT, error))
|
||||
.map_err(|error| ManifestError::Writing(MANIFEST_FILE_NAME, error))
|
||||
}
|
||||
|
||||
fn template(&self) -> String {
|
||||
@ -71,21 +71,21 @@ impl TryFrom<&PathBuf> for Manifest {
|
||||
fn try_from(path: &PathBuf) -> Result<Self, Self::Error> {
|
||||
let mut path = path.to_owned();
|
||||
if path.is_dir() {
|
||||
path.push(PathBuf::from(FILE_NAME_DEFAULT));
|
||||
path.push(PathBuf::from(MANIFEST_FILE_NAME));
|
||||
}
|
||||
|
||||
let mut file =
|
||||
File::open(path).map_err(|error| ManifestError::Opening(FILE_NAME_DEFAULT, error))?;
|
||||
File::open(path).map_err(|error| ManifestError::Opening(MANIFEST_FILE_NAME, error))?;
|
||||
let size = file
|
||||
.metadata()
|
||||
.map_err(|error| ManifestError::Metadata(FILE_NAME_DEFAULT, error))?
|
||||
.map_err(|error| ManifestError::Metadata(MANIFEST_FILE_NAME, error))?
|
||||
.len() as usize;
|
||||
|
||||
let mut buffer = String::with_capacity(size);
|
||||
file.read_to_string(&mut buffer)
|
||||
.map_err(|error| ManifestError::Reading(FILE_NAME_DEFAULT, error))?;
|
||||
.map_err(|error| ManifestError::Reading(MANIFEST_FILE_NAME, error))?;
|
||||
|
||||
Ok(toml::from_str(&buffer)
|
||||
.map_err(|error| ManifestError::Parsing(FILE_NAME_DEFAULT, error))?)
|
||||
.map_err(|error| ManifestError::Parsing(MANIFEST_FILE_NAME, error))?)
|
||||
}
|
||||
}
|
@ -1,9 +1,15 @@
|
||||
pub mod checksum;
|
||||
pub use self::checksum::*;
|
||||
|
||||
pub mod gitignore;
|
||||
pub use self::gitignore::*;
|
||||
|
||||
pub mod main;
|
||||
pub use self::main::*;
|
||||
|
||||
pub mod manifest;
|
||||
pub use self::manifest::*;
|
||||
|
||||
pub mod proof;
|
||||
pub use self::proof::*;
|
||||
|
||||
|
@ -9,4 +9,3 @@ pub mod directories;
|
||||
pub mod errors;
|
||||
pub mod files;
|
||||
pub mod logger;
|
||||
pub mod manifest;
|
||||
|
Loading…
Reference in New Issue
Block a user