From 92bc2379c7866b7d29b8945602d33b405665edb4 Mon Sep 17 00:00:00 2001 From: Severin Siffert Date: Mon, 4 Dec 2023 11:38:58 +0100 Subject: [PATCH] feat: allow hyphen in project names --- CHANGELOG.md | 2 ++ e2e/tests-dfx/new.bash | 2 +- src/dfx/src/commands/new.rs | 2 +- src/dfx/src/util/clap/parsers.rs | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 00b780ca57..a1f8da6597 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -63,6 +63,8 @@ Added the following subcommands: - `dfx cycles transfer ` (transfer cycles from one account to another account) - `dfx cycles top-up ` (send cycles from an account to a canister) +### feat: `dfx new` allows hyphens in project name + ## Dependencies ### Motoko 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() {