Separate global and subcommand-specific options in CLI parser#41
Merged
Separate global and subcommand-specific options in CLI parser#41
Conversation
…ALUES validateOptions() already stops at the first non-option (command) token, so subcommand-specific flags after the command are never checked. However, KNOWN_OPTIONS included subcommand-specific options (--full, --x402, --proxy, --proxy-bearer-token) that don't belong in the global position. This caused misplaced flags to pass pre-validation but then get rejected by Commander with less helpful error messages. Changes: - Split OPTIONS_WITH_VALUES from GLOBAL_OPTIONS_WITH_VALUES so KNOWN_OPTIONS only contains truly global pre-command options - Expand OPTIONS_WITH_VALUES to include all subcommand value-options (--scope, --client-id, --client-secret, -o/--output, --max-size, -r/--payment-required, --amount, --expiry) for correct value-skipping when scanning for command tokens - Remove --full and --x402 from global known-options (they are subcommand-specific and handled by Commander after routing) https://claude.ai/code/session_01BTnA2e1XsqTsM1QQyopyqH
…ons scoping Covers the fix that restricts KNOWN_OPTIONS to global flags: verifies that subcommand-specific options (--full, --x402, --scope, --proxy, -o, etc.) are rejected when placed before a command token but accepted after one. Also adds tests for optionTakesValue and hasSubcommand helpers. https://claude.ai/code/session_01BTnA2e1XsqTsM1QQyopyqH
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Refactored the CLI option parsing logic to properly distinguish between global options (parsed before the first command token) and subcommand-specific options (handled by Commander). This improves error messages when users misplace flags.
Key Changes
OPTIONS_WITH_VALUESinto two constants:GLOBAL_OPTIONS_WITH_VALUES: Options recognized at the global level (-H,--header,--timeout,--profile,--schema,--schema-mode)OPTIONS_WITH_VALUES: Comprehensive list including subcommand-specific options (--scope,--client-id,--client-secret,-o,--output,--max-size,-r,--payment-required,--amount,--expiry) used only for value-skipping during token scanningKNOWN_OPTIONSto only include global options, removing subcommand-specific flags (--full,--x402,--proxy,--proxy-bearer-token)validateOptions()stops at the first non-option tokenImplementation Details
The
OPTIONS_WITH_VALUESconstant now serves a dual purpose: it includes all options that take values (both global and subcommand-specific) so thatoptionTakesValue()correctly skips the next argument during command token scanning, preventing false positives. Meanwhile,KNOWN_OPTIONSis restricted to only global options thatvalidateOptions()should recognize, allowing subcommand-specific options to be properly handled by Commander and producing clearer "Unknown option" errors when flags are misplaced.https://claude.ai/code/session_01BTnA2e1XsqTsM1QQyopyqH