refactor(trail): call --repo guard from RunE, keep guard signature · Entire
refactor(trail): call --repo guard from RunE, keep guard signature
b619765→main·
computermode·yesterday·3 files·+15 added/-12 removed
Revert the ensureTrailRepoHasTarget signature change; invoke the guard from the approval RunE bodies and withNumberedTrail (both have *cobra.Command) instead of threading repoOverride through the string-param helpers.
Co-Authored-By: Claude Opus 4.8 noreply@anthropic.com
Sessions
01KXP5EX32N23QW7H0FGB87WP3View transcript
[?
Guard --repo on Approval and Comment CommandsClaude Code·Opus 4.8·3 steps](/content/gh/entireio/cli/session/57eca55c-1cee-4620-87e0-592d44e64619#timeline-01KXP5EX32N23QW7H0FGB87WP3/index.html)
Changes
3
cmd/entire/cli
Mtrail_approval_cmd.go+9/-6
Mtrail_cmd.go+5/-5
Mtrail_comment_cmd.go+1/-1
58 unmodified lines
59
60
61
62
63
64
62
63
64
32 unmodified lines
97
98
99
100
101
102
103
104
105
14 unmodified lines
120
121
122
123
124
125
126
127
128
11 unmodified lines
140
141
142
143
144
145
146
147
148
7 unmodified lines
156
157
158
153
154
155
159
160
161
58 unmodified lines
if selector != "" && strings.TrimSpace(branch) != "" {
return errors.New("pass a trail selector or --branch, not both")
}
if err := ensureTrailRepoHasTarget(repoOverride, selector != "" || strings.TrimSpace(branch) != "", "pass a trail selector or --branch"); err != nil {
return err
}
req, err := buildApprovalRequest(event, message)
if err != nil {
return err
32 unmodified lines
The trail must be open and have a linked branch.`,
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if err := ensureTrailRepoHasTarget(cmd, selectorFromArgs(args) != "" || strings.TrimSpace(branch) != "", "pass a trail selector or --branch"); err != nil {
return err
}
return submitTrailApproval(cmd.Context(), cmd.OutOrStdout(), cmd.ErrOrStderr(), trailInsecureHTTP(cmd),
trailRepoFlag(cmd), selectorFromArgs(args), branch, "APPROVE", message, "Approved")
},
14 unmodified lines
A reason (--message) is required. The trail must be open and have a linked branch.`,
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if err := ensureTrailRepoHasTarget(cmd, selectorFromArgs(args) != "" || strings.TrimSpace(branch) != "", "pass a trail selector or --branch"); err != nil {
return err
}
return submitTrailApproval(cmd.Context(), cmd.OutOrStdout(), cmd.ErrOrStderr(), trailInsecureHTTP(cmd),
trailRepoFlag(cmd), selectorFromArgs(args), branch, "REQUEST_CHANGES", message, "Requested changes on")
},
11 unmodified lines
Short: "List approval decisions on a trail",
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if err := ensureTrailRepoHasTarget(cmd, selectorFromArgs(args) != "" || strings.TrimSpace(branch) != "", "pass a trail selector or --branch"); err != nil {
return err
}
return runTrailApprovals(cmd.Context(), cmd.OutOrStdout(), cmd.ErrOrStderr(), trailInsecureHTTP(cmd),
trailRepoFlag(cmd), selectorFromArgs(args), branch, jsonOut)
},
7 unmodified lines
if selector != "" && strings.TrimSpace(branch) != "" {
return errors.New("pass a trail selector or --branch, not both")
}
if err := ensureTrailRepoHasTarget(repoOverride, selector != "" || strings.TrimSpace(branch) != "", "pass a trail selector or --branch"); err != nil {
return err
}
// Auth/not-logged-in messages go to stderr; w carries command output only.
return runAuthenticatedTrailAPI(ctx, errW, insecureHTTP, repoOverride, func(ctx context.Context, client *api.Client) error {
found, forge, owner, repoName, err := resolveNumberedTrail(ctx, client, repoOverride, selector, branch)
Mcmd/entire/cli/trail_approval_cmd.go+9/-6
126 unmodified lines
127
128
129
130
131
130
131
132
133
134
30 unmodified lines
165
166
167
168
168
169
170
171
936 unmodified lines
1108
1109
1110
1111
1111
1112
1113
1114
493 unmodified lines
1608
1609
1610
1611
1611
1612
1613
1614
126 unmodified lines
// ensureTrailRepoHasTarget requires an explicit branch or selector when --repo
// targets another repo; otherwise the command would resolve the local branch
// against the wrong repo. hint names the acceptable targets.
func ensureTrailRepoHasTarget(repoOverride string, hasTarget bool, hint string) error {
if repoOverride != "" && !hasTarget {
func ensureTrailRepoHasTarget(cmd *cobra.Command, hasTarget bool, hint string) error {
if trailRepoFlag(cmd) != "" && !hasTarget {
return fmt.Errorf("--repo requires an explicit target: %s", hint)
}
return nil
30 unmodified lines
if selector != "" && trailBranchFlag(cmd) != "" {
return errors.New("pass a trail selector or --branch, not both")
}
if err := ensureTrailRepoHasTarget(trailRepoFlag(cmd), selector != "" || trailBranchFlag(cmd) != "", "pass a trail selector or --branch"); err != nil {
if err := ensureTrailRepoHasTarget(cmd, selector != "" || trailBranchFlag(cmd) != "", "pass a trail selector or --branch"); err != nil {
return err
}
return runTrailShow(cmd.Context(), cmd.OutOrStdout(), cmd.ErrOrStderr(), trailInsecureHTTP(cmd), selector, trailRepoFlag(cmd), trailBranchFlag(cmd))
936 unmodified lines
Short: "Update trail metadata",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) error {
if err := ensureTrailRepoHasTarget(trailRepoFlag(cmd), strings.TrimSpace(branch) != "", "pass --branch"); err != nil {
if err := ensureTrailRepoHasTarget(cmd, strings.TrimSpace(branch) != "", "pass --branch"); err != nil {
return err
}
return runTrailUpdate(cmd.Context(), cmd.OutOrStdout(), cmd.ErrOrStderr(), trailInsecureHTTP(cmd), trailUpdateInputs{
493 unmodified lines
if number > 0 && cmd.Flags().Changed("branch") {
return errors.New("cannot combine a trail <number> with --branch")
}
if err := ensureTrailRepoHasTarget(trailRepoFlag(cmd), number > 0 || strings.TrimSpace(branch) != "", "pass a trail number or --branch"); err != nil {
if err := ensureTrailRepoHasTarget(cmd, number > 0 || strings.TrimSpace(branch) != "", "pass a trail number or --branch"); err != nil {
return err
}
return runTrailDelete(cmd, number, branch, force)