diff --git a/CHANGELOG.md b/CHANGELOG.md index 00b780ca57..88cdabc384 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ Previously, `dfx ledger top-up` only accepted canister principals. Now it accepts both principals and canister names. +### feat: `dfx new` allows hyphens in project name + # 0.15.2 ### fix: `dfx canister delete ` removes the related entry from the canister id store diff --git a/e2e/tests-dfx/new.bash b/e2e/tests-dfx/new.bash index 6559b2d5b6..025e2c62ef 100644 --- a/e2e/tests-dfx/new.bash +++ b/e2e/tests-dfx/new.bash @@ -18,6 +18,7 @@ teardown() { dfx new --no-frontend a_1 dfx new --no-frontend a1 dfx new --no-frontend a1a + dfx new --no-frontend a-b-c } @test "dfx new - bad names" { @@ -29,7 +30,6 @@ teardown() { assert_command_fail dfx new 1_ assert_command_fail dfx new - assert_command_fail dfx new _ - assert_command_fail dfx new a-b-c assert_command_fail dfx new '🕹' assert_command_fail dfx new '不好' assert_command_fail dfx new 'a:b' diff --git a/src/dfx/src/commands/new.rs b/src/dfx/src/commands/new.rs index 99f205b162..8c467e728e 100644 --- a/src/dfx/src/commands/new.rs +++ b/src/dfx/src/commands/new.rs @@ -585,6 +585,7 @@ mod tests { assert!(project_name_parser("A1").is_ok()); assert!(project_name_parser("a_good_name_").is_ok()); assert!(project_name_parser("a_good_name").is_ok()); + assert!(project_name_parser("a-b-c").is_ok()); } #[test] @@ -597,7 +598,6 @@ mod tests { assert!(project_name_parser("1_").is_err()); assert!(project_name_parser("-").is_err()); assert!(project_name_parser("_").is_err()); - assert!(project_name_parser("a-b-c").is_err()); assert!(project_name_parser("🕹").is_err()); assert!(project_name_parser("不好").is_err()); assert!(project_name_parser("a:b").is_err()); diff --git a/src/dfx/src/util/clap/parsers.rs b/src/dfx/src/util/clap/parsers.rs index 9b7184dffc..c8fb6554e6 100644 --- a/src/dfx/src/util/clap/parsers.rs +++ b/src/dfx/src/util/clap/parsers.rs @@ -141,7 +141,7 @@ pub fn project_name_parser(name: &str) -> Result { // Reverses the search here; if there is a character that is not compatible // it is found and an error is returned. let m: Vec<&str> = name - .matches(|x: char| !x.is_ascii_alphanumeric() && x != '_') + .matches(|x: char| !x.is_ascii_alphanumeric() && x != '_' && x != '-') .collect(); if m.is_empty() {