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
3 changes: 2 additions & 1 deletion e2e/edge_case_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,11 @@ func TestJSONOnAckCommand(t *testing.T) {
id := extractIncidentID(t, r.Stdout)
t.Cleanup(func() { runCLI(t, "incident", "close", id) })

// ack is served by the generated twin; --json wraps the OK line as {"message":"..."}.
r = runCLI(t, "incident", "ack", id, "--json")
requireSuccess(t, r)
requireValidJSON(t, r.Stdout)
requireContains(t, r.Stdout, "Acknowledged")
requireContains(t, r.Stdout, "OK: POST /incident/ack")
}

// Test 307: --json on close command
Expand Down
3 changes: 2 additions & 1 deletion e2e/incident_extended_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,10 @@ func TestIncidentAckSingleID(t *testing.T) {
id := extractIncidentID(t, r.Stdout)
t.Cleanup(func() { runCLI(t, "incident", "close", id) })

// Served by the generated twin (positional id → incident_ids).
r = runCLI(t, "incident", "ack", id)
requireSuccess(t, r)
requireContains(t, r.Stdout, "Acknowledged 1 incident(s).")
requireContains(t, r.Stdout, "OK: POST /incident/ack")
}

// Test 204: close single ID
Expand Down
4 changes: 2 additions & 2 deletions e2e/incident_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ func TestIncidentLifecycle(t *testing.T) {
requireContains(t, r.Stdout, "Triggered")
requireContains(t, r.Stdout, name)

// Step 3: Ack
// Step 3: Ack (served by the generated twin; positional id → incident_ids).
r = runCLI(t, "incident", "ack", id)
requireSuccess(t, r)
requireContains(t, r.Stdout, "Acknowledged 1 incident(s).")
requireContains(t, r.Stdout, "OK: POST /incident/ack")

// Step 4: Get - should be Processing
r = runCLI(t, "incident", "get", id)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/flashcatcloud/flashduty-cli
go 1.25.1

require (
github.com/flashcatcloud/go-flashduty v0.5.4-0.20260602051355-7583ebae5b07
github.com/flashcatcloud/go-flashduty v0.5.4-0.20260616041609-da82c4097dd1
github.com/mattn/go-runewidth v0.0.24
github.com/spf13/cobra v1.10.2
github.com/spf13/pflag v1.0.10
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
github.com/clipperhouse/uax29/v2 v2.2.0 h1:ChwIKnQN3kcZteTXMgb1wztSgaU+ZemkgWdohwgs8tY=
github.com/clipperhouse/uax29/v2 v2.2.0/go.mod h1:EFJ2TJMRUaplDxHKj1qAEhCtQPW2tJSwu5BF98AuoVM=
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
github.com/flashcatcloud/go-flashduty v0.5.4-0.20260602051355-7583ebae5b07 h1:bi1rOjR2OY+TovBGabtVOTcEQWlgzU9RfEwlJxU+3n8=
github.com/flashcatcloud/go-flashduty v0.5.4-0.20260602051355-7583ebae5b07/go.mod h1:aA0RtZEs0AYOwwdNKdtVeD8YMOdnmVY1zAlVD+9Ovx8=
github.com/flashcatcloud/go-flashduty v0.5.4-0.20260616041609-da82c4097dd1 h1:K/TceO2NHUPAB8Ew7p/7y6gGDjokNpHyd30uxi8FApc=
github.com/flashcatcloud/go-flashduty v0.5.4-0.20260616041609-da82c4097dd1/go.mod h1:aA0RtZEs0AYOwwdNKdtVeD8YMOdnmVY1zAlVD+9Ovx8=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/mattn/go-runewidth v0.0.24 h1:cpokDiIn0MGnhdHwuWnJBITySJ20QyNGnY2kR/ay2DU=
Expand Down
33 changes: 2 additions & 31 deletions internal/cli/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ func newAlertCmd() *cobra.Command {
cmd.AddCommand(newAlertGetCmd())
cmd.AddCommand(newAlertEventsCmd())
cmd.AddCommand(newAlertTimelineCmd())
cmd.AddCommand(newAlertMergeCmd())
// merge is registered via the generated layer (positional alert-ids fold to
// alert_ids). Flag-name change: --incident (curated) → --incident-id (generated).
return cmd
}

Expand Down Expand Up @@ -303,33 +304,3 @@ func resolveAlertFeedOperators(rc *RunContext, items []flashduty.FeedItem) map[i
}
return out
}

func newAlertMergeCmd() *cobra.Command {
var incidentID, comment string

cmd := &cobra.Command{
Use: "merge <alert_id> [<alert_id2> ...]",
Short: "Merge alerts into an incident",
Args: requireArgs("alert_id"),
RunE: func(cmd *cobra.Command, args []string) error {
return runCommand(cmd, args, func(ctx *RunContext) error {
if _, err := ctx.Client.Alerts.WriteMerge(cmdContext(ctx.Cmd), &flashduty.AlertMergeRequest{
AlertIDs: ctx.Args,
IncidentID: incidentID,
Comment: comment,
}); err != nil {
return err
}

ctx.WriteResult(fmt.Sprintf("Merged %d alert(s) into incident %s.", len(ctx.Args), incidentID))
return nil
})
},
}

cmd.Flags().StringVar(&incidentID, "incident", "", "Target incident ID")
cmd.Flags().StringVar(&comment, "comment", "", "Merge comment")
_ = cmd.MarkFlagRequired("incident")

return cmd
}
18 changes: 18 additions & 0 deletions internal/cli/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ func requireExactArg(name string) cobra.PositionalArgs {
}
}

// optionalArg returns a positional argument validator that accepts zero or one
// argument named name. It backs generated commands whose positional folds into
// an OPTIONAL body field because the operation also accepts an alternative
// lookup key via a flag (e.g. `incident info` takes either the <incident-id>
// positional or --num). Extra arguments are rejected rather than silently
// dropped:
//
// - zero or one arg: ok
// - >1 args: "expects at most one <name>. Usage: ..."
func optionalArg(name string) cobra.PositionalArgs {
return func(cmd *cobra.Command, args []string) error {
if len(args) > 1 {
return fmt.Errorf("expects at most one %s. Usage: %s", name, cmd.UseLine())
}
return nil
}
}

// requireExactlyOneFlag validates that exactly one of the named flags is set.
func requireExactlyOneFlag(cmd *cobra.Command, flagNames ...string) error {
set := 0
Expand Down
9 changes: 6 additions & 3 deletions internal/cli/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,21 @@ type channelRow struct {

func newChannelListCmd() *cobra.Command {
var name string
var teamIDs []int64

cmd := &cobra.Command{
Use: "list",
Short: "List channels",
Long: curatedLong("List channels in the account, optionally filtered by name.", "Channels", "ChannelList"),
Long: curatedLong("List channels in the account, optionally filtered by name or owning team.", "Channels", "ChannelList"),
RunE: func(cmd *cobra.Command, args []string) error {
return runCommand(cmd, args, func(ctx *RunContext) error {
// Legacy parity: the hand-written SDK called /channel/list with an
// empty body and applied the --name filter client-side as a
// case-insensitive substring match. go-flashduty's ChannelName field
// is an exact-match server filter, so we keep the client-side filter
// to preserve behavior.
result, _, err := ctx.Client.Channels.ChannelList(cmdContext(ctx.Cmd), &flashduty.ListChannelsRequest{})
// to preserve behavior. --team-ids, by contrast, is a server-side
// filter on the channel's owning team (empty = all teams, unchanged).
result, _, err := ctx.Client.Channels.ChannelList(cmdContext(ctx.Cmd), &flashduty.ListChannelsRequest{TeamIDs: teamIDs})
if err != nil {
return err
}
Expand Down Expand Up @@ -87,6 +89,7 @@ func newChannelListCmd() *cobra.Command {
}

cmd.Flags().StringVar(&name, "name", "", "Search by name")
cmd.Flags().Int64SliceVar(&teamIDs, "team-ids", nil, "Filter by owning team ID(s), server-side (repeatable or comma-separated)")

return cmd
}
Expand Down
15 changes: 10 additions & 5 deletions internal/cli/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ func TestCommandIncidentUnack(t *testing.T) {
saveAndResetGlobals(t)
stub := newGFStub(t)

// unack is served by the generated twin (positional ids → incident_ids).
out, err := execCommand("incident", "unack", "inc-1", "inc-2")
if err != nil {
t.Fatalf("[incident-unack] unexpected error: %v", err)
Expand All @@ -440,7 +441,7 @@ func TestCommandIncidentUnack(t *testing.T) {
if got, want := strings.Join(stub.bodyStrings("incident_ids"), ","), "inc-1,inc-2"; got != want {
t.Fatalf("[incident-unack] expected ids %q, got %q", want, got)
}
if !strings.Contains(out, "Unacknowledged 2 incident(s).") {
if !strings.Contains(out, "OK: POST /incident/unack") {
t.Fatalf("[incident-unack] unexpected output:\n%s", out)
}
}
Expand All @@ -449,6 +450,7 @@ func TestCommandIncidentWake(t *testing.T) {
saveAndResetGlobals(t)
stub := newGFStub(t)

// wake is served by the generated twin (positional id → incident_ids).
out, err := execCommand("incident", "wake", "inc-1")
if err != nil {
t.Fatalf("[incident-wake] unexpected error: %v", err)
Expand All @@ -459,7 +461,7 @@ func TestCommandIncidentWake(t *testing.T) {
if got, want := strings.Join(stub.bodyStrings("incident_ids"), ","), "inc-1"; got != want {
t.Fatalf("[incident-wake] expected ids %q, got %q", want, got)
}
if !strings.Contains(out, "Restored notifications for 1 incident(s).") {
if !strings.Contains(out, "OK: POST /incident/wake") {
t.Fatalf("[incident-wake] unexpected output:\n%s", out)
}
}
Expand Down Expand Up @@ -500,13 +502,15 @@ func TestCommandIncidentCommentAllows1024UnicodeRunes(t *testing.T) {
}
}

// TestCommandIncidentLifecycleRejectsMoreThan100IDs covers the curated
// commands that still enforce the 100-id batch cap client-side. unack and wake
// were dropped in favor of their generated twins, which carry no client-side
// cap (the backend enforces the limit), so they are intentionally absent here.
func TestCommandIncidentLifecycleRejectsMoreThan100IDs(t *testing.T) {
commands := []struct {
name string
args []string
}{
{name: "unack", args: []string{"incident", "unack"}},
{name: "wake", args: []string{"incident", "wake"}},
{name: "comment", args: []string{"incident", "comment", "--comment", "too many"}},
{name: "remove", args: []string{"incident", "remove"}},
}
Expand Down Expand Up @@ -612,6 +616,7 @@ func TestCommandIncidentDisableMerge(t *testing.T) {
saveAndResetGlobals(t)
stub := newGFStub(t)

// disable-merge is served by the generated twin (positional ids → incident_ids).
out, err := execCommand("incident", "disable-merge", "inc-1", "inc-2")
if err != nil {
t.Fatalf("[incident-disable-merge] unexpected error: %v", err)
Expand All @@ -622,7 +627,7 @@ func TestCommandIncidentDisableMerge(t *testing.T) {
if got, want := strings.Join(stub.bodyStrings("incident_ids"), ","), "inc-1,inc-2"; got != want {
t.Fatalf("[incident-disable-merge] expected ids %q, got %q", want, got)
}
if !strings.Contains(out, "Disabled auto-merge for 2 incident(s).") {
if !strings.Contains(out, "OK: POST /incident/disable-merge") {
t.Fatalf("[incident-disable-merge] unexpected output:\n%s", out)
}
}
Expand Down
22 changes: 15 additions & 7 deletions internal/cli/gen_positional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import (
// the variadic marker; an *_id scalar op renders the single id; the override and
// int cases render their pinned field.
func TestGenPositionalUseLine(t *testing.T) {
// (a) and (b) read the generated constructors directly (the curated commands
// own the live `incident ack`/`incident info` path-names, so the generated
// twins are dropped at registration but still constructible for assertion).
// (a) and (b) call the generated constructors directly so the Use-line
// assertions stay independent of registration order. `incident ack` now
// surfaces the generated twin (curated shadow dropped); `incident info` was
// always generated-only (the curated leaf is named `detail`).
ack := genIncidentsAckCmd()
if got := ack.Use; got != "ack <incident-id> [<id2>...]" {
t.Errorf("ack twin Use = %q, want %q", got, "ack <incident-id> [<id2>...]")
Expand All @@ -28,19 +29,26 @@ func TestGenPositionalUseLine(t *testing.T) {
t.Errorf("ack twin Args rejected one arg: %v", err)
}

// `incident info` pins incident_id as an OPTIONAL positional: the backend
// relaxed incident_id (a lookup may instead pass the 6-char num via --num), so
// the positional is 0-or-1. `info <id>` stays for back-compat; `info` alone
// (with --num) is valid; `info id1 id2` is still rejected.
info := genIncidentsInfoCmd()
if got := info.Use; got != "info <incident-id>" {
t.Errorf("info twin Use = %q, want %q", got, "info <incident-id>")
if got := info.Use; got != "info [<incident-id>]" {
t.Errorf("info twin Use = %q, want %q", got, "info [<incident-id>]")
}
if info.Args == nil {
t.Errorf("info twin has no Args validator")
}
if err := info.Args(info, nil); err == nil {
t.Errorf("info twin Args accepted zero args (want exactly one)")
if err := info.Args(info, nil); err != nil {
t.Errorf("info twin Args rejected zero args (want 0-or-1; --num path): %v", err)
}
if err := info.Args(info, []string{"id1"}); err != nil {
t.Errorf("info twin Args rejected one arg: %v", err)
}
if err := info.Args(info, []string{"id1", "id2"}); err == nil {
t.Errorf("info twin Args accepted two args (want at most one)")
}

// Override cases: merge pins target_incident_id (NOT source_incident_ids);
// war-room detail pins chat_id.
Expand Down
Loading