fix: reject unsupported shells in completion command - #326
Conversation
The completion command declared ValidArgs but validated with
`cobra.MatchAll(cobra.ExactArgs(1))`, so ValidArgs only drove shell
completion and never validation. Any unrecognized shell passed validation,
fell through the switch without matching a case, and left err nil:
$ crs-toolchain completion badshell
$ echo $?
0
A typo produced an empty completion script and a success exit code. Add
`cobra.OnlyValidArgs` so the declared shells are enforced.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan includes up to 1 review per rolling hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe completion command now requires exactly one supported shell argument. Table-driven tests cover valid shells, unsupported shell names, missing arguments, and multiple arguments. ChangesCompletion argument validation
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to The command now rejects unsupported shells instead of succeeding with an empty completion script, with coverage for supported and rejected inputs; no actionable merge-blocking risk remains after normal checks and review. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the 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 |
What
completiondeclaredValidArgsbut validated withcobra.MatchAll(cobra.ExactArgs(1)). Withoutcobra.OnlyValidArgs,ValidArgsonly drives tab-completion and is never enforced. An unrecognized shell passed validation, fell through theswitchwithout matching a case, and lefterrnil:A typo like
zshellproduced an empty completion script and a success exit code, with nothing to indicate anything went wrong. Now:Testing
New table-driven test in
cmd/completion/completion_test.gocovers all four supported shells plus the rejected forms. Removingcobra.OnlyValidArgsmakes it fail.go test ./cmd/...,go vetclean.Note
Found while auditing argument handling across all commands after #325. The two are the same pair of knobs used wrongly in opposite directions: #325 had
OnlyValidArgswith a placeholder inValidArgs, rejecting every real argument, while this one had real values inValidArgsbut noOnlyValidArgs, accepting everything. No other command usesOnlyValidArgs.🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests