Skip to content

Fix MarkFlagRequired rejecting alias flags#248

Merged
jeremy merged 1 commit intomainfrom
fix/flag-alias-required
Mar 11, 2026
Merged

Fix MarkFlagRequired rejecting alias flags#248
jeremy merged 1 commit intomainfrom
fix/flag-alias-required

Conversation

@jeremy
Copy link
Copy Markdown
Member

@jeremy jeremy commented Mar 11, 2026

Summary

  • Remove MarkFlagRequired from three sites where alias flags share a pointer variable (--source/--clone, --position/--pos)
  • Cobra only checks the named flag, so using the alias triggered "required flag not set" before RunE ran
  • All three sites already have manual zero-value guards in RunE, so the MarkFlagRequired calls were redundant
  • Update --source error message to mention both --source and --clone

Test plan

  • TestToolsCreateAcceptsCloneAlias--clone reaches RunE
  • TestToolsCreateRequiresSourceOrClone — omitting both flags produces usage error
  • TestToolsRepositionAcceptsPosAlias--pos reaches RunE
  • TestToolsRepositionRequiresPosition — omitting --position/--pos produces usage error
  • TestTodolistgroupsPositionAcceptsPosAlias — same pattern
  • TestTodolistgroupsPositionRequiresPosition — same pattern
  • make check green

Summary by cubic

Fixes alias flags being rejected by cobra’s required check by removing MarkFlagRequired where aliases share a variable and moving required guards to the top of RunE for immediate, correct errors.

  • Bug Fixes
    • Tools create: --clone now works as an alias for --source; usage error is "--source or --clone is required"; guard runs before any account prompts.
    • Tools reposition and todolistgroups position: --pos now works as an alias for --position; guard runs before other checks.
    • Added tests to confirm aliases reach RunE and missing flags return usage errors.

Written for commit f08648a. Summary will update on new commits.

@jeremy jeremy requested a review from a team as a code owner March 11, 2026 03:31
Copilot AI review requested due to automatic review settings March 11, 2026 03:31
@github-actions github-actions bot added commands CLI command implementations tests Tests (unit and e2e) labels Mar 11, 2026
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 MarkFlagRequired from commands where an alias flag shares the same destination variable.
  • Update the tools create usage error to mention both --source and --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.
@jeremy jeremy force-pushed the fix/flag-alias-required branch from f691522 to f08648a Compare March 11, 2026 03:43
@github-actions github-actions bot added the bug Something isn't working label Mar 11, 2026
@jeremy jeremy merged commit 7a77fd0 into main Mar 11, 2026
25 checks passed
@jeremy jeremy deleted the fix/flag-alias-required branch March 11, 2026 05:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working commands CLI command implementations tests Tests (unit and e2e)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants