feat(update): add -l shorthand for --add-label, matching bd create -l (#6139)
* feat(update): add -l shorthand for --add-label, matching bd create -l
bd create registers labels as StringSliceP("labels", "l", ...), so
`bd create -l foo` works. `bd update -l foo` did not: cobra prints usage
and exits 1 on an unknown shorthand.
That is a correct failure but an easy one to miss. A caller copying the
create form has no reason to expect the flag to differ, and the failure
looks like help output rather than an error in a scrolled log. In one
deployment this left issues believed-labelled that were not, until
someone checked by hand.
Additive: --add-label is unchanged. -l maps to ADD rather than SET
because add is the non-destructive reading and matches what create -l
does on a new issue. -l was previously unregistered on updateCmd (its
shorthands are -s, -t, -e), so there is no collision.
go test ./cmd/bd/ -run Update passes.
Executed-By: mayor
* fix(update): drop backquotes from the --add-label usage string
pflag's UnquoteUsage reads the first backquoted span in a usage string as
the flag's ARGUMENT NAME, so "-l matches `bd create -l`" rendered the flag
as
-l, --add-label bd create -l Add labels (repeatable); ...
in `bd update --help`, where every sibling shows its type. It now reads
`-l, --add-label strings`, matching --remove-label and --set-labels.
Adds the shorthand assertion the review asked for, plus a guard on the
rendered argument name so the backquotes cannot come back unnoticed. Both
verified red before green: restoring the backquotes fails the second test
with the string it renders, dropping -l fails the first.
* build(bazel): list update_add_label_shorthand_test.go in cmd/bd go_test srcs
cmd/bd/BUILD.bazel's go_test enumerates test srcs explicitly rather than
globbing, so the PR's new test file is invisible to `bazel test //...`.
This is review iteration 1's one minor finding (Change Impact / Blast
Radius, gate impact minor).
The drift is merge-target-attributable and this PR is its sole source:
`bazel run //:gazelle -- -mode=diff cmd/bd` (bazel 9.2.0) proposes five
srcs entries and four deps here, but the other four srcs and all four
deps are already present at origin/main -- only this file is absent
there. The reviewers' `if:`-guard uncertainty resolves against the PR:
bazel.yml's `bazel-test` job, which owns the "BUILD files in sync" step,
is gated on `vars.RBE_WEST_WORKERS == 'true' || inputs.rbe == 'off' ||
github.event.pull_request.head.repo.fork == true`, and #6139 is a fork
PR, so the third disjunct holds and the job runs. That step runs
`make bazel-sync` and fails on any `git status --porcelain` output, and
bazel-autofix.yml only pushes its patch to same-repo branches (forks get
an apply recipe), so the drift would not self-heal.
Deviation from the prescribed remedy, deliberate: the finding said to run
`make bazel-sync`, but on this 25-commit-old base the generator would
also add the eight entries that are pure base staleness and already at
the merge target. Only the single PR-owned entry is added here, in
gazelle's own proposed position (sorted, between uow_factory_test.go and
update_claim_proxied_test.go).
Verified: re-running gazelle no longer proposes this file (the other
eight remain untouched); `make bazel-sync-check` rc=0; the 11 TestBazel*
/ TestCheckBuildTags* policy tests pass. Composition asserted inside the
tree CI actually builds -- `git merge-tree --write-tree origin/main
<probe>` rc=0, and the merged cmd/bd/BUILD.bazel differs from
origin/main's by exactly this one line, while the same merge without the
fix is byte-identical to origin/main's (control).
Contributor commits are untouched; no Go file changes.
---------
Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
This commit is contained in:
parent
a1ac9f4dcb
commit
6530c7532f
3 changed files with 67 additions and 1 deletions
|
|
@ -1129,6 +1129,7 @@ go_test(
|
|||
"uninstall_config_test.go",
|
||||
"uow_factory_server_mode_test.go",
|
||||
"uow_factory_test.go",
|
||||
"update_add_label_shorthand_test.go",
|
||||
"update_claim_proxied_test.go",
|
||||
"update_close_policy_proxied_integration_test.go",
|
||||
"update_close_policy_test.go",
|
||||
|
|
|
|||
|
|
@ -973,7 +973,25 @@ func init() {
|
|||
updateCmd.Flags().String("acceptance-criteria", "", "DEPRECATED: use --acceptance")
|
||||
_ = updateCmd.Flags().MarkHidden("acceptance-criteria") // Only fails if flag missing (caught in tests)
|
||||
updateCmd.Flags().IntP("estimate", "e", 0, "Time estimate in minutes (e.g., 60 for 1 hour)")
|
||||
updateCmd.Flags().StringSlice("add-label", nil, "Add labels (repeatable)")
|
||||
// -l is the shorthand for --add-label, matching `bd create -l`.
|
||||
//
|
||||
// WHY: `bd create` registers labels as StringSliceP("labels", "l", ...), so
|
||||
// `bd create -l foo` works. `bd update -l foo` did not, and cobra's response
|
||||
// to an unknown shorthand is to print usage and exit 1. That is a correct
|
||||
// failure, but it is a SILENT one to any caller that does not check the exit
|
||||
// code — and callers copying the `create` form have no reason to expect the
|
||||
// flag to differ. In one deployment this caused issues to be believed
|
||||
// labeled when they were not, for as long as it took someone to check the
|
||||
// label by hand.
|
||||
//
|
||||
// Additive rather than a rename: --add-label keeps working unchanged.
|
||||
// -l maps to ADD (not set) because add is the non-destructive reading and
|
||||
// matches what `create -l` does on a new issue.
|
||||
//
|
||||
// No backquotes in the usage string: pflag reads the first backquoted span
|
||||
// as the flag's ARGUMENT NAME, so "`bd create -l`" here renders the flag as
|
||||
// "-l, --add-label bd create -l" in `bd update --help` instead of "strings".
|
||||
updateCmd.Flags().StringSliceP("add-label", "l", nil, "Add labels (repeatable); -l matches bd create -l")
|
||||
updateCmd.Flags().StringSlice("remove-label", nil, "Remove labels (repeatable)")
|
||||
updateCmd.Flags().StringSlice("set-labels", nil, "Set labels, replacing all existing (repeatable)")
|
||||
updateCmd.Flags().String("parent", "", "New parent issue ID (reparents the issue, use empty string to remove parent)")
|
||||
|
|
|
|||
47
cmd/bd/update_add_label_shorthand_test.go
Normal file
47
cmd/bd/update_add_label_shorthand_test.go
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
//go:build cgo
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
)
|
||||
|
||||
// TestUpdateAddLabelShorthand pins -l to --add-label on `bd update`, and pins it
|
||||
// to the same letter `bd create` uses, since matching that is the whole point of
|
||||
// the flag.
|
||||
func TestUpdateAddLabelShorthand(t *testing.T) {
|
||||
flag := updateCmd.Flags().Lookup("add-label")
|
||||
if flag == nil {
|
||||
t.Fatal("updateCmd should have --add-label flag")
|
||||
}
|
||||
if flag.Shorthand != "l" {
|
||||
t.Errorf("expected shorthand='l', got %q", flag.Shorthand)
|
||||
}
|
||||
|
||||
createFlag := createCmd.Flags().Lookup("labels")
|
||||
if createFlag == nil {
|
||||
t.Fatal("createCmd should have --labels flag")
|
||||
}
|
||||
if flag.Shorthand != createFlag.Shorthand {
|
||||
t.Errorf("update --add-label shorthand %q should match create --labels shorthand %q",
|
||||
flag.Shorthand, createFlag.Shorthand)
|
||||
}
|
||||
}
|
||||
|
||||
// TestUpdateAddLabelUsageHasNoBackquotes guards the rendering of the help line.
|
||||
// pflag's UnquoteUsage takes the first backquoted span in a usage string as the
|
||||
// flag's ARGUMENT NAME, so a usage of "matches `bd create -l`" renders as
|
||||
// "-l, --add-label bd create -l" in `bd update --help` instead of the type name.
|
||||
func TestUpdateAddLabelUsageHasNoBackquotes(t *testing.T) {
|
||||
flag := updateCmd.Flags().Lookup("add-label")
|
||||
if flag == nil {
|
||||
t.Fatal("updateCmd should have --add-label flag")
|
||||
}
|
||||
name, _ := pflag.UnquoteUsage(flag)
|
||||
if name != "strings" {
|
||||
t.Errorf("expected --add-label to render its argument as \"strings\", got %q "+
|
||||
"(a backquoted span in the usage string is read as the argument name)", name)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue