Skip to content

Commit f73886c

Browse files
committed
Fix token command validation and help
1 parent 2ff3806 commit f73886c

4 files changed

Lines changed: 25 additions & 2 deletions

File tree

internal/commands/help.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ var rootCommandGroupTitles = map[string]string{
379379
}
380380

381381
var rootCommandGroups = map[string][]string{
382-
"core": {"auth", "activity", "board", "card", "search"},
382+
"core": {"auth", "token", "activity", "board", "card", "search"},
383383
"collaboration": {"comment", "notification"},
384384
"getting-started": {"setup", "signup"},
385385
"discover": {"doctor", "config", "commands", "version"},

internal/commands/help_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func TestRenderRootHelp(t *testing.T) {
1515
renderHelp(rootCmd, &buf)
1616
out := buf.String()
1717

18-
for _, want := range []string{"CORE COMMANDS", "activity", "GETTING STARTED", "DISCOVER", "FLAGS", "--profile", "LEARN MORE", "Use `fizzy commands` to see the full command catalog.", "implies --json"} {
18+
for _, want := range []string{"CORE COMMANDS", "activity", "token", "GETTING STARTED", "DISCOVER", "FLAGS", "--profile", "LEARN MORE", "Use `fizzy commands` to see the full command catalog.", "implies --json"} {
1919
if !strings.Contains(out, want) {
2020
t.Fatalf("expected root help to contain %q, got:\n%s", want, out)
2121
}

internal/commands/token.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var tokenListCmd = &cobra.Command{
1717
Use: "list",
1818
Short: "List personal access tokens",
1919
Long: "Lists your personal access tokens.",
20+
Args: cobra.NoArgs,
2021
RunE: func(cmd *cobra.Command, args []string) error {
2122
if err := requireAuth(); err != nil {
2223
return err
@@ -55,6 +56,7 @@ var tokenCreateCmd = &cobra.Command{
5556
Use: "create",
5657
Short: "Create a personal access token",
5758
Long: "Creates a new personal access token. The token value is shown once at creation and cannot be retrieved later.",
59+
Args: cobra.NoArgs,
5860
RunE: func(cmd *cobra.Command, args []string) error {
5961
if err := requireAuth(); err != nil {
6062
return err

internal/commands/token_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package commands
2+
3+
import "testing"
4+
5+
func TestTokenListRejectsUnexpectedArgs(t *testing.T) {
6+
if err := tokenListCmd.Args(tokenListCmd, []string{"extra"}); err == nil {
7+
t.Fatal("expected token list to reject unexpected positional args")
8+
}
9+
if err := tokenListCmd.Args(tokenListCmd, []string{}); err != nil {
10+
t.Fatalf("expected token list to allow no positional args, got %v", err)
11+
}
12+
}
13+
14+
func TestTokenCreateRejectsUnexpectedArgs(t *testing.T) {
15+
if err := tokenCreateCmd.Args(tokenCreateCmd, []string{"extra"}); err == nil {
16+
t.Fatal("expected token create to reject unexpected positional args")
17+
}
18+
if err := tokenCreateCmd.Args(tokenCreateCmd, []string{}); err != nil {
19+
t.Fatalf("expected token create to allow no positional args, got %v", err)
20+
}
21+
}

0 commit comments

Comments
 (0)