Skip to content

Separate global and subcommand-specific options in CLI parser#41

Merged
jancurn merged 3 commits intomainfrom
claude/fix-missing-options-oViFz
Mar 8, 2026
Merged

Separate global and subcommand-specific options in CLI parser#41
jancurn merged 3 commits intomainfrom
claude/fix-missing-options-oViFz

Conversation

@jancurn
Copy link
Member

@jancurn jancurn commented Mar 8, 2026

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

  • Split OPTIONS_WITH_VALUES into 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 scanning
  • Updated KNOWN_OPTIONS to only include global options, removing subcommand-specific flags (--full, --x402, --proxy, --proxy-bearer-token)
  • Added clarifying comments explaining the purpose of each constant and how validateOptions() stops at the first non-option token

Implementation Details

The OPTIONS_WITH_VALUES constant now serves a dual purpose: it includes all options that take values (both global and subcommand-specific) so that optionTakesValue() correctly skips the next argument during command token scanning, preventing false positives. Meanwhile, KNOWN_OPTIONS is restricted to only global options that validateOptions() 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

claude and others added 3 commits March 7, 2026 22:25
…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
@jancurn jancurn merged commit 12c8049 into main Mar 8, 2026
6 checks passed
@jancurn jancurn deleted the claude/fix-missing-options-oViFz branch March 12, 2026 14:17
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.

3 participants