Skip to content

Unknown flag-shaped tokens after subcommand silently consumed as positional #1705

Description

@Widthdom

Summary

After the subcommand keyword, unknown flag-shaped tokens (e.g., cdidx search foo --baar where --baar is misspelled) are silently consumed as positional argument strings instead of rejected as unknown flags. The user sees a search for the literal string foo --baar (or worse, no error and an empty result), which is confusing and invites copy-paste mistakes from other CLIs that accept slightly different flag spellings.

Where

  • src/CodeIndex/Cli/QueryCommandRunner.cs:3001-3005 (ParseArgs default branch swallows unknown --* tokens into positional list)
  • Same pattern likely repeats in IndexCommandRunner.cs

Suggested approach

(1) In the parser's default case, if a token starts with - or -- and is not a recognized flag, return a parse error rather than appending to positionals. (2) Pair the rejection with a "Did you mean --<closest>?" hint (companion to #1582 which covers the same for top-level subcommands but not for per-subcommand flags). (3) Add an explicit -- separator to allow callers who genuinely want a leading-dash positional to opt in. (4) Cover with regression tests: search foo --baar exits non-zero with hint; search foo -- --baar succeeds and treats --baar as positional.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions