fizzy-cli 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env +1 -0
- package/.github/workflows/release.yml +29 -0
- package/.github/workflows/tests.yml +24 -0
- package/AGENTS.md +33 -0
- package/CHANGELOG.md +69 -0
- package/Makefile +20 -9
- package/README.md +88 -1
- package/bin/fizzy +0 -0
- package/cmd/account.go +14 -0
- package/cmd/account_list.go +44 -0
- package/cmd/account_list_test.go +118 -0
- package/cmd/board.go +38 -12
- package/cmd/board_create.go +60 -0
- package/cmd/board_create_test.go +158 -0
- package/cmd/board_list.go +18 -32
- package/cmd/board_list_test.go +115 -0
- package/cmd/board_test.go +92 -0
- package/cmd/card.go +24 -0
- package/cmd/card_close.go +46 -0
- package/cmd/card_close_test.go +92 -0
- package/cmd/card_create.go +73 -0
- package/cmd/card_create_test.go +206 -0
- package/cmd/card_delete.go +46 -0
- package/cmd/card_delete_test.go +92 -0
- package/cmd/card_list.go +53 -0
- package/cmd/card_list_test.go +148 -0
- package/cmd/card_reopen.go +46 -0
- package/cmd/card_reopen_test.go +92 -0
- package/cmd/card_show.go +46 -0
- package/cmd/card_show_test.go +92 -0
- package/cmd/card_update.go +74 -0
- package/cmd/card_update_test.go +147 -0
- package/cmd/column.go +14 -0
- package/cmd/column_create.go +80 -0
- package/cmd/column_create_test.go +196 -0
- package/cmd/column_list.go +44 -0
- package/cmd/column_list_test.go +138 -0
- package/cmd/login.go +61 -4
- package/cmd/login_test.go +98 -0
- package/cmd/root.go +15 -4
- package/cmd/use.go +85 -0
- package/cmd/use_test.go +186 -0
- package/docs/API.md +1168 -0
- package/go.mod +23 -2
- package/go.sum +43 -0
- package/internal/api/client.go +463 -0
- package/internal/app/app.go +49 -0
- package/internal/colors/colors.go +32 -0
- package/internal/config/config.go +69 -0
- package/internal/testutil/client.go +26 -0
- package/internal/ui/account_list.go +14 -0
- package/internal/ui/account_selector.go +63 -0
- package/internal/ui/board_list.go +14 -0
- package/internal/ui/card_list.go +14 -0
- package/internal/ui/card_show.go +23 -0
- package/internal/ui/column_list.go +28 -0
- package/internal/ui/format.go +14 -0
- package/main.go +1 -1
- package/package.json +1 -1
- package/scripts/postinstall.js +5 -1
package/cmd/card_show.go
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
package cmd
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"context"
|
|
5
|
+
"fmt"
|
|
6
|
+
"strconv"
|
|
7
|
+
|
|
8
|
+
"github.com/rogeriopvl/fizzy/internal/app"
|
|
9
|
+
"github.com/rogeriopvl/fizzy/internal/ui"
|
|
10
|
+
"github.com/spf13/cobra"
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
var cardShowCmd = &cobra.Command{
|
|
14
|
+
Use: "show <card_id>",
|
|
15
|
+
Short: "Show card details",
|
|
16
|
+
Long: `Retrieve and display details for a specific card`,
|
|
17
|
+
Args: cobra.ExactArgs(1),
|
|
18
|
+
Run: func(cmd *cobra.Command, args []string) {
|
|
19
|
+
if err := handleShowCard(cmd, args[0]); err != nil {
|
|
20
|
+
fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
func handleShowCard(cmd *cobra.Command, cardID string) error {
|
|
26
|
+
a := app.FromContext(cmd.Context())
|
|
27
|
+
if a == nil || a.Client == nil {
|
|
28
|
+
return fmt.Errorf("API client not available")
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
cardNumber, err := strconv.Atoi(cardID)
|
|
32
|
+
if err != nil {
|
|
33
|
+
return fmt.Errorf("card ID must be a number: %w", err)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
card, err := a.Client.GetCard(context.Background(), cardNumber)
|
|
37
|
+
if err != nil {
|
|
38
|
+
return fmt.Errorf("fetching card: %w", err)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return ui.DisplayCard(card)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
func init() {
|
|
45
|
+
cardCmd.AddCommand(cardShowCmd)
|
|
46
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
package cmd
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"context"
|
|
5
|
+
"encoding/json"
|
|
6
|
+
"net/http"
|
|
7
|
+
"net/http/httptest"
|
|
8
|
+
"testing"
|
|
9
|
+
|
|
10
|
+
"github.com/rogeriopvl/fizzy/internal/api"
|
|
11
|
+
"github.com/rogeriopvl/fizzy/internal/app"
|
|
12
|
+
"github.com/rogeriopvl/fizzy/internal/testutil"
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
func TestCardShowCommand(t *testing.T) {
|
|
16
|
+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
17
|
+
if r.URL.Path != "/cards/1" {
|
|
18
|
+
t.Errorf("expected /cards/1, got %s", r.URL.Path)
|
|
19
|
+
}
|
|
20
|
+
if r.Method != http.MethodGet {
|
|
21
|
+
t.Errorf("expected GET, got %s", r.Method)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
auth := r.Header.Get("Authorization")
|
|
25
|
+
if auth != "Bearer test-token" {
|
|
26
|
+
t.Errorf("expected Bearer test-token, got %s", auth)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
w.Header().Set("Content-Type", "application/json")
|
|
30
|
+
response := api.Card{
|
|
31
|
+
ID: "card-123",
|
|
32
|
+
Number: 1,
|
|
33
|
+
Title: "Implement feature",
|
|
34
|
+
Status: "in_progress",
|
|
35
|
+
Description: "This is a test card",
|
|
36
|
+
Tags: []string{"feature", "backend"},
|
|
37
|
+
Golden: false,
|
|
38
|
+
CreatedAt: "2025-01-01T00:00:00Z",
|
|
39
|
+
LastActiveAt: "2025-01-15T10:30:00Z",
|
|
40
|
+
URL: "https://example.com/card/1",
|
|
41
|
+
}
|
|
42
|
+
json.NewEncoder(w).Encode(response)
|
|
43
|
+
}))
|
|
44
|
+
defer server.Close()
|
|
45
|
+
|
|
46
|
+
client := testutil.NewTestClient(server.URL, "", "", "test-token")
|
|
47
|
+
testApp := &app.App{Client: client}
|
|
48
|
+
|
|
49
|
+
cmd := cardShowCmd
|
|
50
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
51
|
+
|
|
52
|
+
if err := handleShowCard(cmd, "1"); err != nil {
|
|
53
|
+
t.Fatalf("handleShowCard failed: %v", err)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
func TestCardShowCommandAPIError(t *testing.T) {
|
|
58
|
+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
59
|
+
w.WriteHeader(http.StatusNotFound)
|
|
60
|
+
w.Write([]byte("Card not found"))
|
|
61
|
+
}))
|
|
62
|
+
defer server.Close()
|
|
63
|
+
|
|
64
|
+
client := testutil.NewTestClient(server.URL, "", "", "test-token")
|
|
65
|
+
testApp := &app.App{Client: client}
|
|
66
|
+
|
|
67
|
+
cmd := cardShowCmd
|
|
68
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
69
|
+
|
|
70
|
+
err := handleShowCard(cmd, "999")
|
|
71
|
+
if err == nil {
|
|
72
|
+
t.Errorf("expected error for API failure")
|
|
73
|
+
}
|
|
74
|
+
if err.Error() != "fetching card: unexpected status code 404: Card not found" {
|
|
75
|
+
t.Errorf("expected API error, got %v", err)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
func TestCardShowCommandNoClient(t *testing.T) {
|
|
80
|
+
testApp := &app.App{}
|
|
81
|
+
|
|
82
|
+
cmd := cardShowCmd
|
|
83
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
84
|
+
|
|
85
|
+
err := handleShowCard(cmd, "1")
|
|
86
|
+
if err == nil {
|
|
87
|
+
t.Errorf("expected error when client not available")
|
|
88
|
+
}
|
|
89
|
+
if err.Error() != "API client not available" {
|
|
90
|
+
t.Errorf("expected 'client not available' error, got %v", err)
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
package cmd
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"context"
|
|
5
|
+
"fmt"
|
|
6
|
+
"strconv"
|
|
7
|
+
|
|
8
|
+
"github.com/rogeriopvl/fizzy/internal/api"
|
|
9
|
+
"github.com/rogeriopvl/fizzy/internal/app"
|
|
10
|
+
"github.com/spf13/cobra"
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
var (
|
|
14
|
+
updateTitle string
|
|
15
|
+
updateDescription string
|
|
16
|
+
updateStatus string
|
|
17
|
+
updateTagIDs []string
|
|
18
|
+
updateLastActiveAt string
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
var cardUpdateCmd = &cobra.Command{
|
|
22
|
+
Use: "update <card_number>",
|
|
23
|
+
Short: "Update a card",
|
|
24
|
+
Long: `Update an existing card's details`,
|
|
25
|
+
Args: cobra.ExactArgs(1),
|
|
26
|
+
Run: func(cmd *cobra.Command, args []string) {
|
|
27
|
+
if err := handleUpdateCard(cmd, args[0]); err != nil {
|
|
28
|
+
fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
func handleUpdateCard(cmd *cobra.Command, cardNumber string) error {
|
|
34
|
+
cardNum, err := strconv.Atoi(cardNumber)
|
|
35
|
+
if err != nil {
|
|
36
|
+
return fmt.Errorf("invalid card number: %w", err)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
a := app.FromContext(cmd.Context())
|
|
40
|
+
if a == nil || a.Client == nil {
|
|
41
|
+
return fmt.Errorf("API client not available")
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Validate that at least one field is provided for update
|
|
45
|
+
if updateTitle == "" && updateDescription == "" && updateStatus == "" && len(updateTagIDs) == 0 && updateLastActiveAt == "" {
|
|
46
|
+
return fmt.Errorf("must provide at least one flag to update (--title, --description, --status, --tag-id, or --last-active-at)")
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
payload := api.UpdateCardPayload{
|
|
50
|
+
Title: updateTitle,
|
|
51
|
+
Description: updateDescription,
|
|
52
|
+
Status: updateStatus,
|
|
53
|
+
TagIDS: updateTagIDs,
|
|
54
|
+
LastActiveAt: updateLastActiveAt,
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
card, err := a.Client.PutCard(context.Background(), cardNum, payload)
|
|
58
|
+
if err != nil {
|
|
59
|
+
return fmt.Errorf("updating card: %w", err)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
fmt.Printf("✓ Card #%d updated successfully\n", card.Number)
|
|
63
|
+
return nil
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
func init() {
|
|
67
|
+
cardUpdateCmd.Flags().StringVarP(&updateTitle, "title", "t", "", "Card title")
|
|
68
|
+
cardUpdateCmd.Flags().StringVarP(&updateDescription, "description", "d", "", "Card description")
|
|
69
|
+
cardUpdateCmd.Flags().StringVar(&updateStatus, "status", "", "Card status")
|
|
70
|
+
cardUpdateCmd.Flags().StringSliceVar(&updateTagIDs, "tag-id", []string{}, "Tag ID (can be used multiple times)")
|
|
71
|
+
cardUpdateCmd.Flags().StringVar(&updateLastActiveAt, "last-active-at", "", "Last active timestamp")
|
|
72
|
+
|
|
73
|
+
cardCmd.AddCommand(cardUpdateCmd)
|
|
74
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
package cmd
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"context"
|
|
5
|
+
"encoding/json"
|
|
6
|
+
"net/http"
|
|
7
|
+
"net/http/httptest"
|
|
8
|
+
"testing"
|
|
9
|
+
|
|
10
|
+
"github.com/rogeriopvl/fizzy/internal/api"
|
|
11
|
+
"github.com/rogeriopvl/fizzy/internal/app"
|
|
12
|
+
"github.com/rogeriopvl/fizzy/internal/testutil"
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
func TestCardUpdateCommand(t *testing.T) {
|
|
16
|
+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
17
|
+
if r.URL.Path != "/cards/1" {
|
|
18
|
+
t.Errorf("expected /cards/1, got %s", r.URL.Path)
|
|
19
|
+
}
|
|
20
|
+
if r.Method != http.MethodPut {
|
|
21
|
+
t.Errorf("expected PUT, got %s", r.Method)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
auth := r.Header.Get("Authorization")
|
|
25
|
+
if auth != "Bearer test-token" {
|
|
26
|
+
t.Errorf("expected Bearer test-token, got %s", auth)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
w.Header().Set("Content-Type", "application/json")
|
|
30
|
+
response := api.Card{
|
|
31
|
+
ID: "card-123",
|
|
32
|
+
Number: 1,
|
|
33
|
+
Title: "Updated card title",
|
|
34
|
+
Status: "published",
|
|
35
|
+
Description: "Updated description",
|
|
36
|
+
Tags: []string{"updated-tag"},
|
|
37
|
+
Golden: false,
|
|
38
|
+
CreatedAt: "2025-01-01T00:00:00Z",
|
|
39
|
+
LastActiveAt: "2025-01-15T10:30:00Z",
|
|
40
|
+
URL: "https://example.com/card/1",
|
|
41
|
+
}
|
|
42
|
+
json.NewEncoder(w).Encode(response)
|
|
43
|
+
}))
|
|
44
|
+
defer server.Close()
|
|
45
|
+
|
|
46
|
+
client := testutil.NewTestClient(server.URL, "", "", "test-token")
|
|
47
|
+
testApp := &app.App{Client: client}
|
|
48
|
+
|
|
49
|
+
cmd := cardUpdateCmd
|
|
50
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
51
|
+
|
|
52
|
+
// Reset flags to defaults
|
|
53
|
+
updateTitle = "Updated card title"
|
|
54
|
+
updateDescription = "Updated description"
|
|
55
|
+
updateStatus = "published"
|
|
56
|
+
updateTagIDs = []string{"updated-tag"}
|
|
57
|
+
|
|
58
|
+
if err := handleUpdateCard(cmd, "1"); err != nil {
|
|
59
|
+
t.Fatalf("handleUpdateCard failed: %v", err)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
func TestCardUpdateCommandAPIError(t *testing.T) {
|
|
64
|
+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
65
|
+
w.WriteHeader(http.StatusNotFound)
|
|
66
|
+
w.Write([]byte("Card not found"))
|
|
67
|
+
}))
|
|
68
|
+
defer server.Close()
|
|
69
|
+
|
|
70
|
+
client := testutil.NewTestClient(server.URL, "", "", "test-token")
|
|
71
|
+
testApp := &app.App{Client: client}
|
|
72
|
+
|
|
73
|
+
cmd := cardUpdateCmd
|
|
74
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
75
|
+
|
|
76
|
+
updateTitle = "Updated card"
|
|
77
|
+
|
|
78
|
+
err := handleUpdateCard(cmd, "999")
|
|
79
|
+
if err == nil {
|
|
80
|
+
t.Errorf("expected error for API failure")
|
|
81
|
+
}
|
|
82
|
+
if err.Error() != "updating card: unexpected status code 404: Card not found" {
|
|
83
|
+
t.Errorf("expected API error, got %v", err)
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
func TestCardUpdateCommandNoClient(t *testing.T) {
|
|
88
|
+
testApp := &app.App{}
|
|
89
|
+
|
|
90
|
+
cmd := cardUpdateCmd
|
|
91
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
92
|
+
|
|
93
|
+
updateTitle = "Updated card"
|
|
94
|
+
|
|
95
|
+
err := handleUpdateCard(cmd, "1")
|
|
96
|
+
if err == nil {
|
|
97
|
+
t.Errorf("expected error when client not available")
|
|
98
|
+
}
|
|
99
|
+
if err.Error() != "API client not available" {
|
|
100
|
+
t.Errorf("expected 'client not available' error, got %v", err)
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
func TestCardUpdateCommandInvalidCardNumber(t *testing.T) {
|
|
105
|
+
testApp := &app.App{}
|
|
106
|
+
|
|
107
|
+
cmd := cardUpdateCmd
|
|
108
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
109
|
+
|
|
110
|
+
updateTitle = "Updated card"
|
|
111
|
+
|
|
112
|
+
err := handleUpdateCard(cmd, "not-a-number")
|
|
113
|
+
if err == nil {
|
|
114
|
+
t.Errorf("expected error for invalid card number")
|
|
115
|
+
}
|
|
116
|
+
if err.Error() != "invalid card number: strconv.Atoi: parsing \"not-a-number\": invalid syntax" {
|
|
117
|
+
t.Errorf("expected invalid card number error, got %v", err)
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
func TestCardUpdateCommandNoFlags(t *testing.T) {
|
|
122
|
+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
123
|
+
w.WriteHeader(http.StatusOK)
|
|
124
|
+
}))
|
|
125
|
+
defer server.Close()
|
|
126
|
+
|
|
127
|
+
client := testutil.NewTestClient(server.URL, "", "", "test-token")
|
|
128
|
+
testApp := &app.App{Client: client}
|
|
129
|
+
|
|
130
|
+
cmd := cardUpdateCmd
|
|
131
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
132
|
+
|
|
133
|
+
// Reset all flags
|
|
134
|
+
updateTitle = ""
|
|
135
|
+
updateDescription = ""
|
|
136
|
+
updateStatus = ""
|
|
137
|
+
updateTagIDs = []string{}
|
|
138
|
+
updateLastActiveAt = ""
|
|
139
|
+
|
|
140
|
+
err := handleUpdateCard(cmd, "1")
|
|
141
|
+
if err == nil {
|
|
142
|
+
t.Errorf("expected error when no flags are provided")
|
|
143
|
+
}
|
|
144
|
+
if err.Error() != "must provide at least one flag to update (--title, --description, --status, --tag-id, or --last-active-at)" {
|
|
145
|
+
t.Errorf("expected 'no flags' error, got %v", err)
|
|
146
|
+
}
|
|
147
|
+
}
|
package/cmd/column.go
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
package cmd
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"context"
|
|
5
|
+
"fmt"
|
|
6
|
+
"strings"
|
|
7
|
+
|
|
8
|
+
"github.com/rogeriopvl/fizzy/internal/api"
|
|
9
|
+
"github.com/rogeriopvl/fizzy/internal/app"
|
|
10
|
+
"github.com/rogeriopvl/fizzy/internal/colors"
|
|
11
|
+
"github.com/spf13/cobra"
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
var (
|
|
15
|
+
columnName string
|
|
16
|
+
columnColor string
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
func buildColorAliases() map[string]api.Color {
|
|
20
|
+
aliases := make(map[string]api.Color)
|
|
21
|
+
for _, colorDef := range colors.All {
|
|
22
|
+
aliases[strings.ToLower(colorDef.Name)] = api.Color(colorDef.CSSValue)
|
|
23
|
+
}
|
|
24
|
+
return aliases
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
func getAvailableColors() string {
|
|
28
|
+
var names []string
|
|
29
|
+
for _, colorDef := range colors.All {
|
|
30
|
+
names = append(names, strings.ToLower(colorDef.Name))
|
|
31
|
+
}
|
|
32
|
+
return strings.Join(names, ", ")
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
var columnCreateCmd = &cobra.Command{
|
|
36
|
+
Use: "create",
|
|
37
|
+
Short: "Create a new column",
|
|
38
|
+
Long: `Create a new column in the selected board. Color is optional.`,
|
|
39
|
+
Run: func(cmd *cobra.Command, args []string) {
|
|
40
|
+
if err := handleCreateColumn(cmd); err != nil {
|
|
41
|
+
fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
func handleCreateColumn(cmd *cobra.Command) error {
|
|
47
|
+
a := app.FromContext(cmd.Context())
|
|
48
|
+
if a == nil || a.Client == nil {
|
|
49
|
+
return fmt.Errorf("API client not available")
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
payload := api.CreateColumnPayload{
|
|
53
|
+
Name: columnName,
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if columnColor != "" {
|
|
57
|
+
colorAliases := buildColorAliases()
|
|
58
|
+
color, ok := colorAliases[columnColor]
|
|
59
|
+
if !ok {
|
|
60
|
+
return fmt.Errorf("invalid color '%s'. Available colors: %s", columnColor, getAvailableColors())
|
|
61
|
+
}
|
|
62
|
+
payload.Color = &color
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
_, err := a.Client.PostColumns(context.Background(), payload)
|
|
66
|
+
if err != nil {
|
|
67
|
+
return fmt.Errorf("creating column: %w", err)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
fmt.Printf("✓ Column '%s' created successfully\n", columnName)
|
|
71
|
+
return nil
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
func init() {
|
|
75
|
+
columnCreateCmd.Flags().StringVarP(&columnName, "name", "n", "", "Column name (required)")
|
|
76
|
+
columnCreateCmd.MarkFlagRequired("name")
|
|
77
|
+
columnCreateCmd.Flags().StringVar(&columnColor, "color", "", fmt.Sprintf("Column color (optional). Available: %s", getAvailableColors()))
|
|
78
|
+
|
|
79
|
+
columnCmd.AddCommand(columnCreateCmd)
|
|
80
|
+
}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
package cmd
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"context"
|
|
5
|
+
"encoding/json"
|
|
6
|
+
"io"
|
|
7
|
+
"net/http"
|
|
8
|
+
"net/http/httptest"
|
|
9
|
+
"testing"
|
|
10
|
+
|
|
11
|
+
"github.com/rogeriopvl/fizzy/internal/api"
|
|
12
|
+
"github.com/rogeriopvl/fizzy/internal/app"
|
|
13
|
+
"github.com/rogeriopvl/fizzy/internal/testutil"
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
func TestColumnCreateCommandSuccess(t *testing.T) {
|
|
17
|
+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
18
|
+
if r.URL.Path != "/boards/board-123/columns" {
|
|
19
|
+
t.Errorf("expected /boards/board-123/columns, got %s", r.URL.Path)
|
|
20
|
+
}
|
|
21
|
+
if r.Method != http.MethodPost {
|
|
22
|
+
t.Errorf("expected POST, got %s", r.Method)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
auth := r.Header.Get("Authorization")
|
|
26
|
+
if auth != "Bearer test-token" {
|
|
27
|
+
t.Errorf("expected Bearer test-token, got %s", auth)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if r.Header.Get("Content-Type") != "application/json" {
|
|
31
|
+
t.Errorf("expected Content-Type: application/json, got %s", r.Header.Get("Content-Type"))
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
body, _ := io.ReadAll(r.Body)
|
|
35
|
+
var payload map[string]api.CreateColumnPayload
|
|
36
|
+
if err := json.Unmarshal(body, &payload); err != nil {
|
|
37
|
+
t.Fatalf("failed to unmarshal request body: %v", err)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
columnPayload := payload["column"]
|
|
41
|
+
if columnPayload.Name != "Todo" {
|
|
42
|
+
t.Errorf("expected name 'Todo', got %s", columnPayload.Name)
|
|
43
|
+
}
|
|
44
|
+
if columnPayload.Color != nil {
|
|
45
|
+
t.Errorf("expected no color, got %v", columnPayload.Color)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
w.WriteHeader(http.StatusCreated)
|
|
49
|
+
w.Header().Set("Location", "/columns/col-123")
|
|
50
|
+
}))
|
|
51
|
+
defer server.Close()
|
|
52
|
+
|
|
53
|
+
client := testutil.NewTestClient(server.URL, "", "board-123", "test-token")
|
|
54
|
+
testApp := &app.App{Client: client}
|
|
55
|
+
|
|
56
|
+
cmd := columnCreateCmd
|
|
57
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
58
|
+
cmd.ParseFlags([]string{"--name", "Todo"})
|
|
59
|
+
|
|
60
|
+
columnName = "Todo"
|
|
61
|
+
columnColor = ""
|
|
62
|
+
|
|
63
|
+
if err := handleCreateColumn(cmd); err != nil {
|
|
64
|
+
t.Fatalf("handleCreateColumn failed: %v", err)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
func TestColumnCreateCommandWithColor(t *testing.T) {
|
|
69
|
+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
70
|
+
if r.Method != http.MethodPost {
|
|
71
|
+
t.Errorf("expected POST, got %s", r.Method)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
body, _ := io.ReadAll(r.Body)
|
|
75
|
+
var payload map[string]api.CreateColumnPayload
|
|
76
|
+
json.Unmarshal(body, &payload)
|
|
77
|
+
|
|
78
|
+
columnPayload := payload["column"]
|
|
79
|
+
if columnPayload.Name != "In Progress" {
|
|
80
|
+
t.Errorf("expected name 'In Progress', got %s", columnPayload.Name)
|
|
81
|
+
}
|
|
82
|
+
if columnPayload.Color == nil {
|
|
83
|
+
t.Error("expected color to be set")
|
|
84
|
+
}
|
|
85
|
+
if *columnPayload.Color != "var(--color-card-4)" {
|
|
86
|
+
t.Errorf("expected color 'var(--color-card-4)', got %s", *columnPayload.Color)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
w.WriteHeader(http.StatusCreated)
|
|
90
|
+
}))
|
|
91
|
+
defer server.Close()
|
|
92
|
+
|
|
93
|
+
client := testutil.NewTestClient(server.URL, "", "board-123", "test-token")
|
|
94
|
+
testApp := &app.App{Client: client}
|
|
95
|
+
|
|
96
|
+
cmd := columnCreateCmd
|
|
97
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
98
|
+
cmd.ParseFlags([]string{"--name", "In Progress", "--color", "lime"})
|
|
99
|
+
|
|
100
|
+
columnName = "In Progress"
|
|
101
|
+
columnColor = "lime"
|
|
102
|
+
|
|
103
|
+
if err := handleCreateColumn(cmd); err != nil {
|
|
104
|
+
t.Fatalf("handleCreateColumn failed: %v", err)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
func TestColumnCreateCommandInvalidColor(t *testing.T) {
|
|
109
|
+
client := testutil.NewTestClient("http://localhost", "", "board-123", "test-token")
|
|
110
|
+
testApp := &app.App{Client: client}
|
|
111
|
+
|
|
112
|
+
cmd := columnCreateCmd
|
|
113
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
114
|
+
cmd.ParseFlags([]string{"--name", "Todo", "--color", "invalid"})
|
|
115
|
+
|
|
116
|
+
columnName = "Todo"
|
|
117
|
+
columnColor = "invalid"
|
|
118
|
+
|
|
119
|
+
err := handleCreateColumn(cmd)
|
|
120
|
+
if err == nil {
|
|
121
|
+
t.Errorf("expected error for invalid color")
|
|
122
|
+
}
|
|
123
|
+
if err.Error() != "invalid color 'invalid'. Available colors: blue, gray, tan, yellow, lime, aqua, violet, purple, pink" {
|
|
124
|
+
t.Errorf("expected invalid color error, got %v", err)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
func TestColumnCreateCommandNoBoard(t *testing.T) {
|
|
129
|
+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
130
|
+
w.WriteHeader(http.StatusInternalServerError)
|
|
131
|
+
}))
|
|
132
|
+
defer server.Close()
|
|
133
|
+
|
|
134
|
+
client := testutil.NewTestClient(server.URL, "", "", "test-token")
|
|
135
|
+
testApp := &app.App{Client: client}
|
|
136
|
+
|
|
137
|
+
cmd := columnCreateCmd
|
|
138
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
139
|
+
cmd.ParseFlags([]string{"--name", "Todo"})
|
|
140
|
+
|
|
141
|
+
columnName = "Todo"
|
|
142
|
+
columnColor = ""
|
|
143
|
+
|
|
144
|
+
err := handleCreateColumn(cmd)
|
|
145
|
+
if err == nil {
|
|
146
|
+
t.Errorf("expected error when board not selected")
|
|
147
|
+
}
|
|
148
|
+
if err.Error() != "creating column: please select a board first with 'fizzy use --board <board_name>'" {
|
|
149
|
+
t.Errorf("expected 'board not selected' error, got %v", err)
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
func TestColumnCreateCommandNoClient(t *testing.T) {
|
|
154
|
+
testApp := &app.App{}
|
|
155
|
+
|
|
156
|
+
cmd := columnCreateCmd
|
|
157
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
158
|
+
cmd.ParseFlags([]string{"--name", "Todo"})
|
|
159
|
+
|
|
160
|
+
columnName = "Todo"
|
|
161
|
+
columnColor = ""
|
|
162
|
+
|
|
163
|
+
err := handleCreateColumn(cmd)
|
|
164
|
+
if err == nil {
|
|
165
|
+
t.Errorf("expected error when client not available")
|
|
166
|
+
}
|
|
167
|
+
if err.Error() != "API client not available" {
|
|
168
|
+
t.Errorf("expected 'client not available' error, got %v", err)
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
func TestColumnCreateCommandAPIError(t *testing.T) {
|
|
173
|
+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
174
|
+
w.WriteHeader(http.StatusInternalServerError)
|
|
175
|
+
w.Write([]byte("Internal Server Error"))
|
|
176
|
+
}))
|
|
177
|
+
defer server.Close()
|
|
178
|
+
|
|
179
|
+
client := testutil.NewTestClient(server.URL, "", "board-123", "test-token")
|
|
180
|
+
testApp := &app.App{Client: client}
|
|
181
|
+
|
|
182
|
+
cmd := columnCreateCmd
|
|
183
|
+
cmd.SetContext(testApp.ToContext(context.Background()))
|
|
184
|
+
cmd.ParseFlags([]string{"--name", "Todo"})
|
|
185
|
+
|
|
186
|
+
columnName = "Todo"
|
|
187
|
+
columnColor = ""
|
|
188
|
+
|
|
189
|
+
err := handleCreateColumn(cmd)
|
|
190
|
+
if err == nil {
|
|
191
|
+
t.Errorf("expected error for API failure")
|
|
192
|
+
}
|
|
193
|
+
if err.Error() != "creating column: unexpected status code 500: Internal Server Error" {
|
|
194
|
+
t.Errorf("expected API error, got %v", err)
|
|
195
|
+
}
|
|
196
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
package cmd
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"context"
|
|
5
|
+
"fmt"
|
|
6
|
+
|
|
7
|
+
"github.com/rogeriopvl/fizzy/internal/app"
|
|
8
|
+
"github.com/rogeriopvl/fizzy/internal/ui"
|
|
9
|
+
"github.com/spf13/cobra"
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
var columnListCmd = &cobra.Command{
|
|
13
|
+
Use: "list",
|
|
14
|
+
Short: "List all columns",
|
|
15
|
+
Long: `Retrieve and display all columns in the selected board`,
|
|
16
|
+
Run: func(cmd *cobra.Command, args []string) {
|
|
17
|
+
if err := handleListColumns(cmd); err != nil {
|
|
18
|
+
fmt.Fprintf(cmd.OutOrStderr(), "Error: %v\n", err)
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
func handleListColumns(cmd *cobra.Command) error {
|
|
24
|
+
a := app.FromContext(cmd.Context())
|
|
25
|
+
if a == nil || a.Client == nil {
|
|
26
|
+
return fmt.Errorf("API client not available")
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
columns, err := a.Client.GetColumns(context.Background())
|
|
30
|
+
if err != nil {
|
|
31
|
+
return fmt.Errorf("fetching columns: %w", err)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if len(columns) == 0 {
|
|
35
|
+
fmt.Println("No columns found")
|
|
36
|
+
return nil
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return ui.DisplayColumns(columns)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
func init() {
|
|
43
|
+
columnCmd.AddCommand(columnListCmd)
|
|
44
|
+
}
|