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
25 changes: 25 additions & 0 deletions internal/cli/flag_consistency_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package cli

import (
"testing"

"github.com/spf13/cobra"
)

// TestPageImpliesLimit walks the full command tree and asserts that any
// command exposing a --page flag also exposes --limit. Agents transfer flag
// knowledge across command groups; a paginated list without --limit forces
// trial-and-error round-trips (seen in prod: `member list --limit` failing
// with "unknown flag").
func TestPageImpliesLimit(t *testing.T) {
var walk func(cmd *cobra.Command)
walk = func(cmd *cobra.Command) {
if cmd.Flags().Lookup("page") != nil && cmd.Flags().Lookup("limit") == nil {
t.Errorf("%s registers --page but not --limit", cmd.CommandPath())
}
for _, sub := range cmd.Commands() {
walk(sub)
}
}
walk(rootCmd)
}
11 changes: 10 additions & 1 deletion internal/cli/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ func newMemberCmd() *cobra.Command {
func newMemberListCmd() *cobra.Command {
var name, email string
var page int
var limit int
var roleID int64
var orderBy string
var asc bool

cmd := &cobra.Command{
Use: "list",
Expand All @@ -39,9 +42,12 @@ func newMemberListCmd() *cobra.Command {
query = email
}
req := &flashduty.MemberListRequest{
Query: query,
Query: query,
Orderby: orderBy,
Asc: asc,
}
req.Page = page
req.Limit = limit
if roleID != 0 {
req.RoleID = uint64(roleID)
}
Expand Down Expand Up @@ -83,6 +89,9 @@ func newMemberListCmd() *cobra.Command {
cmd.Flags().StringVar(&name, "name", "", "Search by name")
cmd.Flags().StringVar(&email, "email", "", "Search by email")
cmd.Flags().IntVar(&page, "page", 1, "Page number")
cmd.Flags().IntVar(&limit, "limit", 20, "Page size, max 100 (default 20)")
cmd.Flags().StringVar(&orderBy, "orderby", "", "Sort field: created_at, updated_at, member_name")
cmd.Flags().BoolVar(&asc, "asc", false, "Sort in ascending order")
cmd.Flags().Int64Var(&roleID, "role-id", 0, "Filter to members holding this role ID")

return cmd
Expand Down
Loading