Fix MarkFlagRequired rejecting alias flags#248
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f691522611
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
Fixes a Cobra MarkFlagRequired edge case where required validation only applied to the canonical flag name, causing alias flags (e.g., --clone, --pos) to be rejected before RunE executes. The PR removes redundant MarkFlagRequired calls and relies on existing RunE guards, adding regression tests for the alias paths.
Changes:
- Remove
MarkFlagRequiredfrom commands where an alias flag shares the same destination variable. - Update the tools create usage error to mention both
--sourceand--clone. - Add tests covering alias acceptance and missing-flag usage errors for tools and todolistgroups repositioning.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| internal/commands/tools.go | Removes MarkFlagRequired for --source and --position and updates the --source missing-flag usage message. |
| internal/commands/todolistgroups.go | Removes MarkFlagRequired for --position where --pos is an alias. |
| internal/commands/tools_test.go | Adds tests for --clone/--pos alias behavior and missing-flag usage errors. |
| internal/commands/todolistgroups_test.go | Adds tests for --pos alias behavior and missing-flag usage errors. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Cobra's MarkFlagRequired only checks the named flag, so when two flags share a pointer variable (--source/--clone, --position/--pos), using the alias causes "required flag not set" before RunE runs. All three sites already have manual zero-value guards in RunE, so the MarkFlagRequired calls are redundant and harmful. Remove them. Move flag guards before ensureAccount so that missing-flag errors are reported immediately, without prompting for account selection first. Also update the --source error message to mention both flag names.
f691522 to
f08648a
Compare
Summary
MarkFlagRequiredfrom three sites where alias flags share a pointer variable (--source/--clone,--position/--pos)RunEranRunE, so theMarkFlagRequiredcalls were redundant--sourceerror message to mention both--sourceand--cloneTest plan
TestToolsCreateAcceptsCloneAlias—--clonereaches RunETestToolsCreateRequiresSourceOrClone— omitting both flags produces usage errorTestToolsRepositionAcceptsPosAlias—--posreaches RunETestToolsRepositionRequiresPosition— omitting--position/--posproduces usage errorTestTodolistgroupsPositionAcceptsPosAlias— same patternTestTodolistgroupsPositionRequiresPosition— same patternmake checkgreenSummary by cubic
Fixes alias flags being rejected by
cobra’s required check by removingMarkFlagRequiredwhere aliases share a variable and moving required guards to the top ofRunEfor immediate, correct errors.--clonenow works as an alias for--source; usage error is "--source or --clone is required"; guard runs before any account prompts.--posnow works as an alias for--position; guard runs before other checks.RunEand missing flags return usage errors.Written for commit f08648a. Summary will update on new commits.