fix leo new

This commit is contained in:
collin 2022-07-15 15:35:19 -07:00
parent e82631103d
commit 8dde478664
3 changed files with 22 additions and 14 deletions

View File

@ -162,7 +162,7 @@ impl<'a> CodeGenerator<'a> {
format!("{}.{}", name, type_)
} else {
// foo; // no visibility for interfaces
name.to_string()
name
}
} else {
unreachable!("All composite types should be known at this phase of compilation")

View File

@ -18,7 +18,8 @@ use crate::{
commands::{Command, ALEO_CLI_COMMAND},
context::Context,
};
use leo_errors::{CliError, Result};
use leo_errors::{CliError, PackageError, Result};
use leo_package::build::BuildDirectory;
use leo_package::package::Package;
use aleo::commands::New as AleoNew;
@ -47,19 +48,27 @@ impl Command for New {
fn apply(self, context: Context, _: Self::Input) -> Result<Self::Output> {
tracing::info!("Starting...");
let path = context.dir()?;
// Derive the program directory path.
let mut package_path = path.clone();
package_path.push(&self.name);
// Initialize the Leo package in the directory created by `aleo new`.
Package::initialize(&self.name, &package_path)?;
// Create the Leo build/ directory
let build_directory = BuildDirectory::create(&path)?;
// Change the cwd to the Leo build/ directory to compile aleo files.
std::env::set_current_dir(&build_directory)
.map_err(|err| PackageError::failed_to_set_cwd(build_directory.display(), err))?;
// Call the `aleo new` command from the Aleo SDK.
let command =
AleoNew::try_parse_from(&[ALEO_CLI_COMMAND, &self.name]).map_err(CliError::failed_to_parse_aleo_new)?;
let result = command.parse().map_err(CliError::failed_to_execute_aleo_new)?;
// Derive the program directory path.
let mut path = context.dir()?;
path.push(&self.name);
// Initialize the Leo package in the directory created by `aleo new`.
Package::initialize(&self.name, &path)?;
// todo: modify the readme file to recommend building with `leo build`.
// Log the output of the `aleo new` command.

View File

@ -168,7 +168,7 @@ impl Package {
// Create the source directory.
SourceDirectory::create(path)?;
// Create the input directory.
// Create the inputs directory.
InputsDirectory::create(path)?;
// Create the input file in the inputs directory.
@ -176,11 +176,10 @@ impl Package {
// Create the main file in the source directory.
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.as_os_str()).into());
}
Ok(())