Skip to content

Commit

Permalink
feat: allow hyphen in project names
Browse files Browse the repository at this point in the history
  • Loading branch information
sesi200 committed Dec 4, 2023
1 parent 20583ed commit 92bc237
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ Added the following subcommands:
- `dfx cycles transfer <to> <amount>` (transfer cycles from one account to another account)
- `dfx cycles top-up <to> <amount>` (send cycles from an account to a canister)

### feat: `dfx new` allows hyphens in project name

## Dependencies

### Motoko
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

0 comments on commit 92bc237

Please sign in to comment.