Skip to content

Commit 58e8230

Browse files
committed
feat(cli): accept positional <id> on team get (completes PR#50 rollout)
PR#50 added positional IDs to incident/alert curated commands but left team get requiring --id. Agents using the positional form got syntax errors (seen 3× in sess_5Cg5UV6WpTY8Yt4VSbHrLw steps 60-61). MaximumNArgs(1) + PreRunE bypass when arg present is consistent with the PR#50 pattern.
1 parent e82d588 commit 58e8230

2 files changed

Lines changed: 43 additions & 4 deletions

File tree

internal/cli/team.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,23 +92,35 @@ func newTeamGetCmd() *cobra.Command {
9292
)
9393

9494
cmd := &cobra.Command{
95-
Use: "get",
95+
Use: "get [<id>]",
9696
Short: "Get team detail",
9797
Long: curatedLong(`Get detailed information about a specific team.
9898
99-
Specify the team by exactly one of: --id, --name, or --ref-id.
99+
Specify the team by positional ID, or by exactly one of: --id, --name, or --ref-id.
100100
The output includes team metadata, member list, and audit information.
101101
102102
Examples:
103+
flashduty team get 123
103104
flashduty team get --id 123
104105
flashduty team get --name "SRE Team"
105106
flashduty team get --ref-id "hr-dept-42"
106107
flashduty team get --id 123 --json`, "Teams", "ReadInfo"),
108+
Args: cobra.MaximumNArgs(1),
107109
PreRunE: func(cmd *cobra.Command, args []string) error {
110+
if len(args) == 1 {
111+
return nil
112+
}
108113
return requireExactlyOneFlag(cmd, "id", "name", "ref-id")
109114
},
110115
RunE: func(cmd *cobra.Command, args []string) error {
111116
return runCommand(cmd, args, func(ctx *RunContext) error {
117+
if len(ctx.Args) == 1 {
118+
id, err := strconv.ParseInt(ctx.Args[0], 10, 64)
119+
if err != nil {
120+
return fmt.Errorf("invalid team id %q: must be a number", ctx.Args[0])
121+
}
122+
teamID = id
123+
}
112124
team, _, err := ctx.Client.Teams.ReadInfo(cmdContext(ctx.Cmd), &flashduty.TeamInfoRequest{
113125
TeamID: uint64(teamID),
114126
TeamName: teamName,
@@ -122,8 +134,6 @@ Examples:
122134
return ctx.Printer.Print(team, nil)
123135
}
124136

125-
// TeamItem carries only member person IDs; resolve names/emails
126-
// in one batch to replicate the legacy member display.
127137
members := resolveTeamMemberInfos(ctx, team.PersonIDs)
128138
printTeamDetail(ctx.Writer, team, members)
129139
return nil

internal/cli/team_get_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package cli
2+
3+
import "testing"
4+
5+
func TestTeamGetAcceptsPositionalID(t *testing.T) {
6+
cmd := newTeamGetCmd()
7+
// MaximumNArgs(1): two positional args should be rejected
8+
if cmd.Args != nil {
9+
if err := cmd.Args(cmd, []string{"123456", "789"}); err == nil {
10+
t.Fatal("team get should reject two positional args")
11+
}
12+
}
13+
}
14+
15+
func TestTeamGetNoArgNoFlagFails(t *testing.T) {
16+
cmd := newTeamGetCmd()
17+
err := cmd.PreRunE(cmd, []string{})
18+
if err == nil {
19+
t.Fatal("expected error when no positional arg and no flag provided")
20+
}
21+
}
22+
23+
func TestTeamGetPositionalArgBypassesPreRunE(t *testing.T) {
24+
cmd := newTeamGetCmd()
25+
err := cmd.PreRunE(cmd, []string{"123456"})
26+
if err != nil {
27+
t.Fatalf("PreRunE should succeed with positional arg, got: %v", err)
28+
}
29+
}

0 commit comments

Comments
 (0)