Skip to content

Commit

Permalink
Relax command name format (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg committed Jun 27, 2022
1 parent 563adc4 commit 0ecab58
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions acmd.go
Expand Up @@ -39,7 +39,7 @@ type Command struct {
// Do will be invoked.
Do func(ctx context.Context, args []string) error

// subcommands of the command.
// Subcommands of the command.
Subcommands []Command

// IsHidden reports whether command should not be show in help. Default false.
Expand Down Expand Up @@ -241,7 +241,7 @@ func isStringValid(s string) bool {
}
for _, c := range s {
if !(('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z') ||
('0' <= c && c <= '9') || c == '-' || c == '_') {
('0' <= c && c <= '9') || c == '-' || c == '_' || c == ':') {
return false
}
}
Expand Down
6 changes: 5 additions & 1 deletion acmd_test.go
Expand Up @@ -204,6 +204,10 @@ func TestRunnerInit(t *testing.T) {
cfg Config
wantErrStr string
}{
{
cmds: []Command{{Name: "app:create", Do: nopFunc}},
wantErrStr: ``,
},
{
cmds: []Command{{Name: "", Do: nopFunc}},
wantErrStr: `command "" must contains only letters, digits, - and _`,
Expand Down Expand Up @@ -276,7 +280,7 @@ func TestRunnerInit(t *testing.T) {
for _, tc := range testCases {
err := RunnerOf(tc.cmds, tc.cfg).Run()

if got := err.Error(); !strings.Contains(got, tc.wantErrStr) {
if got := err.Error(); tc.wantErrStr != "" && !strings.Contains(got, tc.wantErrStr) {
t.Fatalf("want %q got %q", tc.wantErrStr, got)
}
}
Expand Down

0 comments on commit 0ecab58

Please sign in to comment.