Skip to content

Commit

Permalink
fix: reserved keywords are checked before creating dir with forc new (F…
Browse files Browse the repository at this point in the history
  • Loading branch information
kayagokalp authored Dec 10, 2022
1 parent 15991fb commit 3bb4e13
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions forc/src/cli/commands/new.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::{cli::init::Command as InitCommand, ops::forc_init::init};
use anyhow::{bail, Result};
use anyhow::{anyhow, bail, Result};
use clap::Parser;
use std::path::Path;
use forc_util::validate_name;
use std::path::{Path, PathBuf};

/// Create a new Forc project at `<path>`.
#[derive(Debug, Parser)]
Expand Down Expand Up @@ -43,6 +44,20 @@ pub(crate) fn exec(command: Command) -> Result<()> {
path,
} = command;

match &name {
Some(name) => validate_name(name, "project name")?,
None => {
// If there is no name specified for the project, the last component of the `path` (directory name)
// will be used by default so we should also check that.
let project_path = PathBuf::from(&path);
let directory_name = project_path
.file_name()
.ok_or_else(|| anyhow!("missing path for new command"))?
.to_string_lossy();
validate_name(&directory_name, "project_name")?;
}
}

let dir_path = Path::new(&path);
if dir_path.exists() {
bail!(
Expand Down

0 comments on commit 3bb4e13

Please sign in to comment.