Skip to content

fix(cmd): fail fast when marking an unknown flag required#1771

Open
AmanGIT07 wants to merge 1 commit into
mainfrom
fix/cmd-required-flags
Open

fix(cmd): fail fast when marking an unknown flag required#1771
AmanGIT07 wants to merge 1 commit into
mainfrom
fix/cmd-required-flags

Conversation

@AmanGIT07

Copy link
Copy Markdown
Contributor

Summary

MarkFlagRequired returns an error only when the named flag is not defined on the command. All 49 call sites in cmd/ discarded it, so a mistyped or renamed flag name silently made the flag optional.

Changes

  • Add mustMarkRequired in cmd/flags.go: marks each named flag required and panics if the flag does not exist, naming the flag and the command
  • Replace all 49 cmd.MarkFlagRequired(...) calls across 11 files with mustMarkRequired(cmd, ...)
  • Add cmd/flags_test.go covering both paths

Technical Details

The helper runs during command construction, before flag parsing. A wrong flag name now crashes every CLI run and every go test ./cmd/ instead of shipping a command whose required flag is quietly optional. Current flag names are all valid: the existing cmd tests construct every command and none of the calls panic.

Test Plan

  • go test ./cmd/ passes
  • Build and type checking passes

MarkFlagRequired errors only when the named flag does not exist, and
every call site discarded that error, silently making the flag optional.
Route all calls through a helper that panics on an unknown name.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 17, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
frontier Ready Ready Preview, Comment Jul 17, 2026 10:36am

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c96c93b9-002d-420a-b1f8-a192f05d0539

📥 Commits

Reviewing files that changed from the base of the PR and between cfe2cf3 and e26a581.

📒 Files selected for processing (13)
  • cmd/flags.go
  • cmd/flags_test.go
  • cmd/group.go
  • cmd/namespace.go
  • cmd/organization.go
  • cmd/permission.go
  • cmd/policy.go
  • cmd/preferences.go
  • cmd/project.go
  • cmd/reconcile.go
  • cmd/role.go
  • cmd/seed.go
  • cmd/user.go

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved required-flag validation across CLI commands.
    • Commands now fail clearly when required flags are missing or invalid.
  • Tests
    • Added coverage for successful required-flag registration, missing flags, and invalid flag names.

Walkthrough

Adds and tests a shared mustMarkRequired helper, then replaces direct Cobra required-flag calls across resource and auxiliary CLI commands.

Changes

Required flag validation

Layer / File(s) Summary
Helper implementation and validation
cmd/flags.go, cmd/flags_test.go
Adds mustMarkRequired with panic handling for invalid flags and tests valid and unknown flag behavior.
Resource command required flags
cmd/group.go, cmd/organization.go, cmd/permission.go, cmd/policy.go, cmd/project.go, cmd/role.go, cmd/user.go
Routes resource command file and header required-flag registration through the shared helper.
Auxiliary command required flags
cmd/namespace.go, cmd/preferences.go, cmd/reconcile.go, cmd/seed.go
Routes namespace, preferences, reconcile, and seed required-flag registration through the shared helper.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: rohilsurana

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 29574013505

Coverage increased (+0.006%) to 46.116%

Details

  • Coverage increased (+0.006%) from the base build.
  • Patch coverage: 53 of 53 lines across 12 files are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 38325
Covered Lines: 17674
Line Coverage: 46.12%
Coverage Strength: 13.83 hits per line

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants