Skip to content
Open
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
7 changes: 7 additions & 0 deletions internal/commands/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var (
listQuiet bool
listSort string
listFull bool
listLimit int
)

var listCmd = &cobra.Command{
Expand Down Expand Up @@ -121,6 +122,11 @@ Search Syntax (--search/-S):
// Sort beans
sortBeans(beans, listSort, cfg)

// Apply limit
if listLimit > 0 && len(beans) > listLimit {
beans = beans[:listLimit]
}

// JSON output (flat list)
if listJSON {
if !listFull {
Expand Down Expand Up @@ -311,5 +317,6 @@ func RegisterListCmd(root *cobra.Command) {
listCmd.Flags().BoolVarP(&listQuiet, "quiet", "q", false, "Only output IDs (one per line)")
listCmd.Flags().StringVar(&listSort, "sort", "", "Sort by: created, updated, status, priority, id (default: status, priority, type, title)")
listCmd.Flags().BoolVar(&listFull, "full", false, "Include bean body in JSON output")
listCmd.Flags().IntVar(&listLimit, "limit", 0, "Limit the number of beans returned")
root.AddCommand(listCmd)
}
33 changes: 33 additions & 0 deletions internal/commands/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,36 @@ func TestTruncate(t *testing.T) {
}
}


func TestListLimit(t *testing.T) {
beans := []*bean.Bean{
{ID: "1"},
{ID: "2"},
{ID: "3"},
{ID: "4"},
{ID: "5"},
}

tests := []struct {
name string
limit int
want int
}{
{"no limit", 0, 5},
{"limit less than total", 3, 3},
{"limit exactly total", 5, 5},
{"limit greater than total", 10, 5},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
out := beans
if tt.limit > 0 && len(out) > tt.limit {
out = out[:tt.limit]
}
if len(out) != tt.want {
t.Errorf("limit=%d: got len=%d, want %d", tt.limit, len(out), tt.want)
}
})
}
}