Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .surface
Original file line number Diff line number Diff line change
Expand Up @@ -4388,6 +4388,7 @@ FLAG basecamp projects list --todolist type=string
FLAG basecamp projects list --verbose type=count
FLAG basecamp projects show --account type=string
FLAG basecamp projects show --agent type=bool
FLAG basecamp projects show --all type=bool
FLAG basecamp projects show --cache-dir type=string
FLAG basecamp projects show --count type=bool
FLAG basecamp projects show --hints type=bool
Expand Down
25 changes: 23 additions & 2 deletions internal/commands/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,12 @@ func updateProjectsCache(projects []basecamp.Project, cacheDir string) {
}

func newProjectsShowCmd() *cobra.Command {
return &cobra.Command{
var all bool

cmd := &cobra.Command{
Use: "show <id>",
Short: "Show project details",
Long: "Display detailed information about a project including its dock (the set of enabled tools: message board, to-dos, schedule, etc.).",
Long: "Display detailed information about a project including its dock (the set of enabled tools: message board, to-dos, schedule, etc.).\n\nBy default only enabled tools are shown. Use --all to include disabled tools.",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
app := appctx.FromContext(cmd.Context())
Expand All @@ -214,6 +216,10 @@ func newProjectsShowCmd() *cobra.Command {
return convertSDKError(err)
}

if !all {
project.Dock = filterEnabledDock(project.Dock)
}

return app.OK(project,
output.WithEntity("project"),
output.WithBreadcrumbs(
Expand All @@ -231,6 +237,21 @@ func newProjectsShowCmd() *cobra.Command {
)
},
}

cmd.Flags().BoolVar(&all, "all", false, "Show all dock tools including disabled")

return cmd
}

// filterEnabledDock returns only the enabled dock items.
func filterEnabledDock(dock []basecamp.DockItem) []basecamp.DockItem {
var enabled []basecamp.DockItem
for _, item := range dock {
if item.Enabled {
enabled = append(enabled, item)
}
}
return enabled
}

func newProjectsCreateCmd() *cobra.Command {
Expand Down
65 changes: 53 additions & 12 deletions internal/presenter/format.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package presenter

import (
"encoding/json"
"fmt"
"sort"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -134,38 +137,76 @@ func formatPeople(val any) string {
}

// formatDock formats a project dock (array of tool maps) as a multi-line listing.
// Items are sorted by their position field to match the order configured in the web UI.
func formatDock(val any) string {
arr, ok := val.([]any)
if !ok || len(arr) == 0 {
// NormalizeData may produce []map[string]any or []any; accept both.
var items []map[string]any
switch v := val.(type) {
case []map[string]any:
items = v
case []any:
for _, item := range v {
if m, ok := item.(map[string]any); ok {
items = append(items, m)
}
}
}
if len(items) == 0 {
return ""
}

// Sort by position so the output matches the web UI order.
// Enabled items (with positions) come first; disabled items sort to the end.
sort.SliceStable(items, func(i, j int) bool {
return dockPosition(items[i]) < dockPosition(items[j])
})

var lines []string
for _, item := range arr {
m, ok := item.(map[string]any)
if !ok {
continue
}
if enabled, ok := m["enabled"].(bool); ok && !enabled {
continue
for _, m := range items {
disabled := false
if e, ok := m["enabled"].(bool); ok && !e {
disabled = true
}

title, _ := m["title"].(string)
name, _ := m["name"].(string)
id := formatText(m["id"])
if title == "" {
title = name
}

var line string
if name != "" && id != "" {
lines = append(lines, fmt.Sprintf("%s (%s, ID: %s)", title, name, id))
line = fmt.Sprintf("%s (%s, ID: %s)", title, name, id)
} else if name != "" {
lines = append(lines, fmt.Sprintf("%s (%s)", title, name))
line = fmt.Sprintf("%s (%s)", title, name)
} else {
lines = append(lines, title)
line = title
}
if disabled {
line += " [disabled]"
}
lines = append(lines, line)
}
return strings.Join(lines, "\n")
}

// dockPosition extracts the position from a dock item map.
// Items without a position sort to the end (max int).
func dockPosition(m map[string]any) int {
switch v := m["position"].(type) {
case float64:
return int(v)
case int:
return v
case json.Number:
if n, err := strconv.Atoi(v.String()); err == nil {
return n
}
}
return 1<<31 - 1
}

// formatPerson formats a single person object (map with "name" field).
func formatPerson(val any) string {
if m, ok := val.(map[string]any); ok {
Expand Down
63 changes: 60 additions & 3 deletions internal/presenter/format_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package presenter

import (
"encoding/json"
"testing"
)

Expand All @@ -17,14 +18,14 @@ func TestFormatDock(t *testing.T) {
}
}

func TestFormatDockSkipsDisabled(t *testing.T) {
func TestFormatDockAnnotatesDisabled(t *testing.T) {
dock := []any{
map[string]any{"name": "todoset", "title": "To-dos", "enabled": true, "id": float64(1)},
map[string]any{"name": "todoset", "title": "To-dos", "enabled": true, "id": float64(1), "position": float64(1)},
map[string]any{"name": "vault", "title": "Docs & Files", "enabled": false, "id": float64(3)},
}

got := formatDock(dock)
want := "To-dos (todoset, ID: 1)"
want := "To-dos (todoset, ID: 1)\nDocs & Files (vault, ID: 3) [disabled]"
if got != want {
t.Errorf("formatDock(with disabled) = %q, want %q", got, want)
}
Expand All @@ -43,6 +44,62 @@ func TestFormatDockDefaultsEnabledWhenAbsent(t *testing.T) {
}
}

func TestFormatDockSortsByPosition(t *testing.T) {
dock := []any{
map[string]any{"name": "vault", "title": "Docs & Files", "enabled": true, "id": float64(3), "position": float64(3)},
map[string]any{"name": "todoset", "title": "To-dos", "enabled": true, "id": float64(1), "position": float64(1)},
map[string]any{"name": "message_board", "title": "Message Board", "enabled": true, "id": float64(2), "position": float64(2)},
}

got := formatDock(dock)
want := "To-dos (todoset, ID: 1)\nMessage Board (message_board, ID: 2)\nDocs & Files (vault, ID: 3)"
if got != want {
t.Errorf("formatDock(position sort) = %q, want %q", got, want)
}
}

func TestFormatDockItemsWithoutPositionSortLast(t *testing.T) {
dock := []any{
map[string]any{"name": "vault", "title": "Docs & Files", "enabled": true, "id": float64(3)},
map[string]any{"name": "todoset", "title": "To-dos", "enabled": true, "id": float64(1), "position": float64(1)},
}

got := formatDock(dock)
want := "To-dos (todoset, ID: 1)\nDocs & Files (vault, ID: 3)"
if got != want {
t.Errorf("formatDock(missing position) = %q, want %q", got, want)
}
}

func TestFormatDockAcceptsMapSlice(t *testing.T) {
// NormalizeData produces []map[string]any with json.Number positions.
dock := []map[string]any{
{"name": "vault", "title": "Docs & Files", "enabled": true, "id": json.Number("3"), "position": json.Number("3")},
{"name": "todoset", "title": "To-dos", "enabled": true, "id": json.Number("1"), "position": json.Number("1")},
{"name": "message_board", "title": "Message Board", "enabled": true, "id": json.Number("2"), "position": json.Number("2")},
}

got := formatDock(dock)
want := "To-dos (todoset, ID: 1)\nMessage Board (message_board, ID: 2)\nDocs & Files (vault, ID: 3)"
if got != want {
t.Errorf("formatDock([]map with json.Number) = %q, want %q", got, want)
}
}

func TestFormatDockDisabledSortAfterEnabled(t *testing.T) {
dock := []map[string]any{
{"name": "schedule", "title": "Schedule", "enabled": false, "id": json.Number("3")},
{"name": "todoset", "title": "To-dos", "enabled": true, "id": json.Number("1"), "position": json.Number("2")},
{"name": "message_board", "title": "Message Board", "enabled": true, "id": json.Number("2"), "position": json.Number("1")},
}

got := formatDock(dock)
want := "Message Board (message_board, ID: 2)\nTo-dos (todoset, ID: 1)\nSchedule (schedule, ID: 3) [disabled]"
if got != want {
t.Errorf("formatDock(disabled sort last) = %q, want %q", got, want)
}
}

func TestFormatDockEmpty(t *testing.T) {
if got := formatDock([]any{}); got != "" {
t.Errorf("formatDock(empty) = %q, want empty", got)
Expand Down
Loading