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
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
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
15 changes: 11 additions & 4 deletions internal/cli/gen_positional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,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
4 changes: 4 additions & 0 deletions internal/cli/zz_generated_channels.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions internal/cli/zz_generated_incidents.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading