This commit is contained in:
Pranav Gaddamadugu 2024-05-31 18:13:50 -07:00
parent 745d7268ae
commit a23f31d0b7
4 changed files with 51 additions and 39 deletions

View File

@ -93,7 +93,7 @@ create_messages!(
@backtraced
failed_to_load_instructions {
args: (error: impl Display),
msg: format!("Failed to load compiled Aleo instructions into an Aleo file.\nSnarkVM Error: {error}"),
msg: format!("Failed to load compiled Aleo instructions into an Aleo file.\nError: {error}"),
help: Some("Generated Aleo instructions have been left in `main.aleo`".to_string()),
}
@ -107,84 +107,84 @@ create_messages!(
@backtraced
failed_to_execute_build {
args: (error: impl Display),
msg: format!("Failed to execute the `build` command.\nSnarkVM Error: {error}"),
msg: format!("Failed to execute the `build` command.\nError: {error}"),
help: None,
}
@backtraced
failed_to_execute_new {
args: (error: impl Display),
msg: format!("Failed to execute the `new` command.\nSnarkVM Error: {error}"),
msg: format!("Failed to execute the `new` command.\nError: {error}"),
help: None,
}
@backtraced
failed_to_execute_run {
args: (error: impl Display),
msg: format!("Failed to execute the `run` command.\nSnarkVM Error: {error}"),
msg: format!("Failed to execute the `run` command.\nError: {error}"),
help: None,
}
@backtraced
failed_to_execute_node {
args: (error: impl Display),
msg: format!("Failed to execute the `node` command.\nSnarkVM Error: {error}"),
msg: format!("Failed to execute the `node` command.\nError: {error}"),
help: None,
}
@backtraced
failed_to_execute_deploy {
args: (error: impl Display),
msg: format!("Failed to execute the `deploy` command.\nSnarkVM Error: {error}"),
msg: format!("Failed to execute the `deploy` command.\nError: {error}"),
help: None,
}
@backtraced
failed_to_parse_new {
args: (error: impl Display),
msg: format!("Failed to parse the `new` command.\nSnarkVM Error: {error}"),
msg: format!("Failed to parse the `new` command.\nError: {error}"),
help: None,
}
@backtraced
failed_to_parse_run {
args: (error: impl Display),
msg: format!("Failed to parse the `run` command.\nSnarkVM Error: {error}"),
msg: format!("Failed to parse the `run` command.\nError: {error}"),
help: None,
}
@backtraced
failed_to_parse_node {
args: (error: impl Display),
msg: format!("Failed to parse the `node` command.\nSnarkVM Error: {error}"),
msg: format!("Failed to parse the `node` command.\nError: {error}"),
help: None,
}
@backtraced
failed_to_parse_deploy {
args: (error: impl Display),
msg: format!("Failed to parse the `deploy` command.\nSnarkVM Error: {error}"),
msg: format!("Failed to parse the `deploy` command.\nError: {error}"),
help: None,
}
@backtraced
failed_to_parse_execute {
args: (error: impl Display),
msg: format!("Failed to parse the `execute` command.\nSnarkVM Error: {error}"),
msg: format!("Failed to parse the `execute` command.\nError: {error}"),
help: None,
}
@backtraced
failed_to_execute_execute {
args: (error: impl Display),
msg: format!("Failed to execute the `execute` command.\nSnarkVM Error: {error}"),
msg: format!("Failed to execute the `execute` command.\nError: {error}"),
help: None,
}
@backtraced
failed_to_parse_seed {
args: (error: impl Display),
msg: format!("Failed to parse the seed string for account.\nSnarkVM Error: {error}"),
msg: format!("Failed to parse the seed string for account.\nError: {error}"),
help: None,
}
@ -198,14 +198,14 @@ create_messages!(
@backtraced
failed_to_parse_private_key {
args: (error: impl Display),
msg: format!("Failed to parse private key.\nSnarkVM Error: {error}"),
msg: format!("Failed to parse private key.\nError: {error}"),
help: None,
}
@backtraced
failed_to_execute_account {
args: (error: impl Display),
msg: format!("Failed to execute the `account` command.\nSnarkVM Error: {error}"),
msg: format!("Failed to execute the `account` command.\nError: {error}"),
help: None,
}

View File

@ -198,8 +198,8 @@ create_messages!(
/// For when the package failed to initialize.
@backtraced
failed_to_initialize_package {
args: (package: impl Display, path: impl Debug),
msg: format!("failed to initialize package {package} {path:?}"),
args: (package: impl Display, path: impl Debug, error: impl Display),
msg: format!("Failed to initialize package {package} at {path:?}. Error: {error}"),
help: None,
}
@ -207,7 +207,7 @@ create_messages!(
@backtraced
invalid_package_name {
args: (package: impl Display),
msg: format!("invalid project name {package}"),
msg: format!("Invalid project name {package}"),
help: None,
}

View File

@ -1,20 +1,20 @@
[[package]]
name = "board.aleo"
location = "local"
path = "board"
path = "/Users/pranav/work/Aleo/leo/examples/battleship/board"
checksum = "da94274230d0c0c3deb96d80e07ad9db8bbf53264286c14cc3231b7a8b7ef380"
dependencies = []
[[package]]
name = "move.aleo"
location = "local"
path = "move"
path = "/Users/pranav/work/Aleo/leo/examples/battleship/move"
checksum = "7d9fef5fe083eb24376e63935855e4ec709c17fb5ee46a0bb4594b0f9ef8eb08"
dependencies = []
[[package]]
name = "verify.aleo"
location = "local"
path = "verify"
path = "/Users/pranav/work/Aleo/leo/examples/battleship/verify"
checksum = "2c2035ebd70500b7e5a9a6198bed1a1163cd1ddfd09128db8f4c16cf23ad2c62"
dependencies = []

View File

@ -16,7 +16,6 @@
use crate::{
build::BuildDirectory,
inputs::InputsDirectory,
root::{Env, Gitignore},
source::{MainFile, SourceDirectory},
};
@ -128,37 +127,50 @@ impl Package {
/// Creates a Leo package at the given path
pub fn initialize<N: Network>(package_name: &str, path: &Path) -> Result<()> {
// Verify that the .gitignore file does not exist.
if !Gitignore::exists_at(path) {
// Create the .gitignore file.
Gitignore::new().write_to(path)?;
// Construct the path to the package directory.
let path = path.join(package_name);
// Verify that there is no existing directory at the path.
if path.exists() {
return Err(
PackageError::failed_to_initialize_package(package_name, &path, "Directory already exists").into()
);
}
// Verify that the .env file does not exist.
if !Env::<N>::exists_at(path) {
// Create the .env file.
Env::<N>::new()?.write_to(path)?;
}
// Create the package directory.
std::fs::create_dir(&path).map_err(|e| PackageError::failed_to_initialize_package(package_name, &path, e))?;
// Change the current working directory to the package directory.
std::env::set_current_dir(&path)
.map_err(|e| PackageError::failed_to_initialize_package(package_name, &path, e))?;
// Create the .gitignore file.
Gitignore::new().write_to(&path)?;
// Create the .env file.
Env::<N>::new()?.write_to(&path)?;
// Create a manifest.
let manifest = Manifest::default(package_name);
manifest.write_to_dir(path.to_path_buf())?;
// Create the source directory.
SourceDirectory::create(path)?;
// Create the inputs directory.
InputsDirectory::create(path)?;
SourceDirectory::create(&path)?;
// Create the Leo build/ directory
BuildDirectory::create(path)?;
BuildDirectory::create(&path)?;
// Create the main file in the source directory.
MainFile::new(package_name).write_to(path)?;
MainFile::new(package_name).write_to(&path)?;
// Next, verify that a valid Leo package has been initialized in this directory
if !Self::is_initialized(package_name, path) {
return Err(PackageError::failed_to_initialize_package(package_name, path.as_os_str()).into());
if !Self::is_initialized(package_name, &path) {
return Err(PackageError::failed_to_initialize_package(
package_name,
&path,
"Failed to correctly initialize package",
)
.into());
}
Ok(())