Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow hyphen in project names #3463

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <canister id>` removes the related entry from the canister id store
Expand Down
2 changes: 1 addition & 1 deletion e2e/tests-dfx/new.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand All @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion src/dfx/src/commands/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/dfx/src/util/clap/parsers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ pub fn project_name_parser(name: &str) -> Result<String, String> {
// 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() {
Expand Down
Loading