mirror of
https://github.com/AleoHQ/leo.git
synced 2024-12-25 18:42:26 +03:00
rename input -> inputs
This commit is contained in:
parent
1e56b3a5f6
commit
589988b76a
@ -71,7 +71,7 @@ impl CLI for InitCommand {
|
||||
}
|
||||
} else {
|
||||
// Create the input directory
|
||||
InputDirectory::create(&path)?;
|
||||
InputsDirectory::create(&path)?;
|
||||
|
||||
// Verify the input file does not exist
|
||||
let input_file = InputFile::new(&package_name);
|
||||
|
@ -88,7 +88,7 @@ impl CLI for NewCommand {
|
||||
LibFile::new(&package_name).write_to(&path)?;
|
||||
} else {
|
||||
// Create the input directory
|
||||
InputDirectory::create(&path)?;
|
||||
InputsDirectory::create(&path)?;
|
||||
|
||||
// Create the input file in the input directory
|
||||
InputFile::new(&package_name).write_to(&path)?;
|
||||
|
@ -22,7 +22,7 @@ pub enum CLIError {
|
||||
InitError(InitError),
|
||||
|
||||
#[error("{}", _0)]
|
||||
InputDirectoryError(InputDirectoryError),
|
||||
InputDirectoryError(InputsDirectoryError),
|
||||
|
||||
#[error("{}", _0)]
|
||||
InputFileError(InputFileError),
|
||||
@ -102,8 +102,8 @@ impl From<InitError> for CLIError {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<InputDirectoryError> for CLIError {
|
||||
fn from(error: InputDirectoryError) -> Self {
|
||||
impl From<InputsDirectoryError> for CLIError {
|
||||
fn from(error: InputsDirectoryError) -> Self {
|
||||
log::error!("{}\n", error);
|
||||
CLIError::InputDirectoryError(error)
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std::{ffi::OsString, fs::FileType, io};
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum InputDirectoryError {
|
||||
pub enum InputsDirectoryError {
|
||||
#[error("creating: {}", _0)]
|
||||
Creating(io::Error),
|
||||
|
||||
|
@ -1,39 +1,39 @@
|
||||
use crate::{errors::InputDirectoryError, inputs::INPUT_FILE_EXTENSION};
|
||||
use crate::{errors::InputsDirectoryError, inputs::INPUT_FILE_EXTENSION};
|
||||
|
||||
use std::{fs, path::PathBuf};
|
||||
|
||||
pub static INPUT_DIRECTORY_NAME: &str = "inputs/";
|
||||
pub static INPUTS_DIRECTORY_NAME: &str = "inputs/";
|
||||
|
||||
pub struct InputDirectory;
|
||||
pub struct InputsDirectory;
|
||||
|
||||
impl InputDirectory {
|
||||
impl InputsDirectory {
|
||||
/// Creates a directory at the provided path with the default directory name.
|
||||
pub fn create(path: &PathBuf) -> Result<(), InputDirectoryError> {
|
||||
pub fn create(path: &PathBuf) -> Result<(), InputsDirectoryError> {
|
||||
let mut path = path.to_owned();
|
||||
if path.is_dir() && !path.ends_with(INPUT_DIRECTORY_NAME) {
|
||||
path.push(PathBuf::from(INPUT_DIRECTORY_NAME));
|
||||
if path.is_dir() && !path.ends_with(INPUTS_DIRECTORY_NAME) {
|
||||
path.push(PathBuf::from(INPUTS_DIRECTORY_NAME));
|
||||
}
|
||||
|
||||
fs::create_dir_all(&path).map_err(InputDirectoryError::Creating)
|
||||
fs::create_dir_all(&path).map_err(InputsDirectoryError::Creating)
|
||||
}
|
||||
|
||||
/// Returns a list of files in the source directory.
|
||||
pub fn files(path: &PathBuf) -> Result<Vec<PathBuf>, InputDirectoryError> {
|
||||
pub fn files(path: &PathBuf) -> Result<Vec<PathBuf>, InputsDirectoryError> {
|
||||
let mut path = path.to_owned();
|
||||
path.push(PathBuf::from(INPUT_DIRECTORY_NAME));
|
||||
let directory = fs::read_dir(&path).map_err(InputDirectoryError::Reading)?;
|
||||
path.push(PathBuf::from(INPUTS_DIRECTORY_NAME));
|
||||
let directory = fs::read_dir(&path).map_err(InputsDirectoryError::Reading)?;
|
||||
|
||||
let mut file_paths = Vec::new();
|
||||
for file_entry in directory.into_iter() {
|
||||
let file_entry = file_entry.map_err(InputDirectoryError::GettingFileEntry)?;
|
||||
let file_entry = file_entry.map_err(InputsDirectoryError::GettingFileEntry)?;
|
||||
let file_path = file_entry.path();
|
||||
|
||||
// Verify that the entry is structured as a valid file
|
||||
let file_type = file_entry
|
||||
.file_type()
|
||||
.map_err(|error| InputDirectoryError::GettingFileType(file_path.as_os_str().to_owned(), error))?;
|
||||
.map_err(|error| InputsDirectoryError::GettingFileType(file_path.as_os_str().to_owned(), error))?;
|
||||
if !file_type.is_file() {
|
||||
return Err(InputDirectoryError::InvalidFileType(
|
||||
return Err(InputsDirectoryError::InvalidFileType(
|
||||
file_path.as_os_str().to_owned(),
|
||||
file_type,
|
||||
));
|
||||
@ -42,9 +42,9 @@ impl InputDirectory {
|
||||
// Verify that the file has the default file extension
|
||||
let file_extension = file_path
|
||||
.extension()
|
||||
.ok_or_else(|| InputDirectoryError::GettingFileExtension(file_path.as_os_str().to_owned()))?;
|
||||
.ok_or_else(|| InputsDirectoryError::GettingFileExtension(file_path.as_os_str().to_owned()))?;
|
||||
if file_extension != INPUT_FILE_EXTENSION {
|
||||
return Err(InputDirectoryError::InvalidFileExtension(
|
||||
return Err(InputsDirectoryError::InvalidFileExtension(
|
||||
file_path.as_os_str().to_owned(),
|
||||
file_extension.to_owned(),
|
||||
));
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! The `program.in` file.
|
||||
|
||||
use crate::{errors::InputFileError, inputs::INPUT_DIRECTORY_NAME};
|
||||
use crate::{errors::InputFileError, inputs::INPUTS_DIRECTORY_NAME};
|
||||
|
||||
use serde::Deserialize;
|
||||
use std::{
|
||||
@ -58,8 +58,8 @@ b: u32 = 2;
|
||||
fn setup_file_path(&self, path: &PathBuf) -> PathBuf {
|
||||
let mut path = path.to_owned();
|
||||
if path.is_dir() {
|
||||
if !path.ends_with(INPUT_DIRECTORY_NAME) {
|
||||
path.push(PathBuf::from(INPUT_DIRECTORY_NAME));
|
||||
if !path.ends_with(INPUTS_DIRECTORY_NAME) {
|
||||
path.push(PathBuf::from(INPUTS_DIRECTORY_NAME));
|
||||
}
|
||||
path.push(PathBuf::from(format!("{}{}", self.package_name, INPUT_FILE_EXTENSION)));
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! The `program.state` file.
|
||||
|
||||
use crate::{errors::StateFileError, inputs::INPUT_DIRECTORY_NAME};
|
||||
use crate::{errors::StateFileError, inputs::INPUTS_DIRECTORY_NAME};
|
||||
|
||||
use serde::Deserialize;
|
||||
use std::{
|
||||
@ -79,8 +79,8 @@ leaf_randomness: u8[32] = [0u8; 32];
|
||||
fn setup_file_path(&self, path: &PathBuf) -> PathBuf {
|
||||
let mut path = path.to_owned();
|
||||
if path.is_dir() {
|
||||
if !path.ends_with(INPUT_DIRECTORY_NAME) {
|
||||
path.push(PathBuf::from(INPUT_DIRECTORY_NAME));
|
||||
if !path.ends_with(INPUTS_DIRECTORY_NAME) {
|
||||
path.push(PathBuf::from(INPUTS_DIRECTORY_NAME));
|
||||
}
|
||||
path.push(PathBuf::from(format!("{}{}", self.package_name, STATE_FILE_EXTENSION)));
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
use crate::{
|
||||
errors::ZipFileError,
|
||||
imports::IMPORTS_DIRECTORY_NAME,
|
||||
inputs::{INPUT_DIRECTORY_NAME, INPUT_FILE_EXTENSION},
|
||||
inputs::{INPUTS_DIRECTORY_NAME, INPUT_FILE_EXTENSION},
|
||||
outputs::{
|
||||
CHECKSUM_FILE_EXTENSION,
|
||||
OUTPUTS_DIRECTORY_NAME,
|
||||
@ -111,7 +111,7 @@ impl ZipFile {
|
||||
|
||||
fn is_excluded(path: &Path) -> bool {
|
||||
// excluded directories: `input`, `output`, `imports`
|
||||
if path.ends_with(INPUT_DIRECTORY_NAME.trim_end_matches("/"))
|
||||
if path.ends_with(INPUTS_DIRECTORY_NAME.trim_end_matches("/"))
|
||||
| path.ends_with(OUTPUTS_DIRECTORY_NAME.trim_end_matches("/"))
|
||||
| path.ends_with(IMPORTS_DIRECTORY_NAME.trim_end_matches("/"))
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user