fix(cli): reject unknown flags before -- in exec/check subcommands#202
fix(cli): reject unknown flags before -- in exec/check subcommands#202
-- in exec/check subcommands#202Conversation
`trailing_var_arg = true` + `allow_hyphen_values = true` caused clap to silently absorb unknown flags (e.g. `--config`) into the `command` Vec instead of reporting an error. This meant typos like `runok check --config foo break` would exit 0 with unexpected behavior. Add a pre-parse validation step that inspects raw process args to detect unrecognized flags before `--`. Once a non-flag token (the command name) is encountered, all subsequent tokens are treated as command arguments. Flags after `--` are always allowed since they belong to the target command. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a subtle but critical issue in the command-line interface where unknown flags for Highlights
Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #202 +/- ##
=======================================
Coverage 89.26% 89.26%
=======================================
Files 47 48 +1
Lines 9046 9093 +47
=======================================
+ Hits 8075 8117 +42
- Misses 971 976 +5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Review feedback pointed out three issues: 1. `known_flags` and `flags_with_value` were defined as separate arrays, creating a maintenance risk if a new flag with a value is added to one but not the other. 2. Manual index management with a `while` loop was less idiomatic than using iterators. 3. `check` subcommand validation errors returned exit code 1 instead of the documented exit code 2. Consolidate flag definitions into a single `FlagDef` struct, replace the index-based loop with an iterator, and use the correct exit code per subcommand convention. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…alidation The pre-parse validator rejected `--help`/`-h` and `--version`/`-V` because they were not listed in the subcommand-specific flag definitions. These flags are automatically added by clap and must pass through validation so clap can handle them normally. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…lper CLAUDE.md requires using the shlex crate for shell splitting. The test helper was using split_whitespace which would break on quoted arguments. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Why
--config) passed toexec/checksubcommands were silently absorbed into thecommandVec by clap, causing exit 0 with no errortrailing_var_arg = true+allow_hyphen_values = truecombination treated unknown flags as positional argumentsWhat
--runok check ls -la(without--) continue to work