fix(cmd): fail fast when marking an unknown flag required#1771
fix(cmd): fail fast when marking an unknown flag required#1771AmanGIT07 wants to merge 1 commit into
Conversation
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>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (13)
📝 WalkthroughSummary by CodeRabbit
WalkthroughAdds and tests a shared ChangesRequired flag validation
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
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. Comment |
Coverage Report for CI Build 29574013505Coverage increased (+0.006%) to 46.116%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
Summary
MarkFlagRequiredreturns 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
mustMarkRequiredincmd/flags.go: marks each named flag required and panics if the flag does not exist, naming the flag and the commandcmd.MarkFlagRequired(...)calls across 11 files withmustMarkRequired(cmd, ...)cmd/flags_test.gocovering both pathsTechnical 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