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

Relax command name format #29

Merged
merged 2 commits into from Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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