Skip to content

Commit

Permalink
chore: allow omitting the --name flag in nargo init
Browse files Browse the repository at this point in the history
  • Loading branch information
f01dab1e committed Oct 8, 2023
1 parent 03c7923 commit 2c1db97
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions tooling/nargo_cli/src/cli/init_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf>,

/// Name of the package [default: current directory name]
#[clap(long)]
name: Option<CrateName>,
Expand Down Expand Up @@ -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()))?
}
};
Expand All @@ -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(())
}

Expand Down

0 comments on commit 2c1db97

Please sign in to comment.