diff --git a/tooling/nargo_cli/src/cli/init_cmd.rs b/tooling/nargo_cli/src/cli/init_cmd.rs index 2091ac89f9c..9a16f8a7a9b 100644 --- a/tooling/nargo_cli/src/cli/init_cmd.rs +++ b/tooling/nargo_cli/src/cli/init_cmd.rs @@ -12,6 +12,9 @@ use std::path::PathBuf; /// Create a Noir project in the current directory. #[derive(Debug, Clone, Args)] pub(crate) struct InitCommand { + /// The path to save the new project + path: Option, + /// Name of the package [default: current directory name] #[clap(long)] name: Option, @@ -68,10 +71,20 @@ pub(crate) fn run( args: InitCommand, config: NargoConfig, ) -> Result<(), CliError> { + let package_dir = if let Some(path) = args.path { + config.program_dir.join(&path) + } else { + config.program_dir + }; + + if package_dir.exists() { + return Err(CliError::DestinationAlreadyExists(package_dir)); + } + let package_name = match args.name { Some(name) => name, None => { - let name = config.program_dir.file_name().unwrap().to_str().unwrap(); + let name = package_dir.file_name().unwrap().to_str().unwrap(); name.parse().map_err(|_| CliError::InvalidPackageName(name.into()))? } }; @@ -83,7 +96,7 @@ pub(crate) fn run( } else { PackageType::Binary }; - initialize_project(config.program_dir, package_name, package_type); + initialize_project(package_dir, package_name, package_type); Ok(()) }