Skip to content

Auto-suggest corrections for misspelled flags and subcommands #51

Description

@aryasaatvik

Problem

Bunli silently ignores unknown flags (parser.ts line 51: continue). Misspelled subcommands get suggestions (already implemented via Levenshtein), but misspelled flags do not. The Levenshtein threshold is also too generous at 3.

Solution

Add "did you mean?" suggestions for both flags and subcommands using Levenshtein distance ≤ 2:

$ mycli depoly --verbos

Error: unknown subcommand "depoly"
  Did you mean "deploy"?

Error: unknown option "--verbos"
  Did you mean "--verbose"?

Design

  1. Tighten threshold in utils/levenshtein.ts: change from 3 to 2

  2. Track unknown flags in parser.ts:

    • Instead of continue on unknown flags, compute suggestion via findSuggestion(name, Object.keys(options))
    • Add to ParsedArgs result:
    unknownFlags?: Array<{ flag: string; suggestion?: string }>
  3. Integrate with error accumulation (Issue feat: type-safe code generation and comprehensive documentation overhaul #3):

    • Unknown flags become additional errors in the aggregate report
    • Short flag suggestions use the shortToName map
  4. Subcommands already have Levenshtein — just tighten the threshold

Edge cases

  • Global flags are merged before parsing → --help never triggers suggestion
  • Flags after -- are positional → no suggestions
  • Short flags: if -x unknown, suggest based on known short flag values

Files

  • packages/core/src/utils/levenshtein.ts — threshold 3 → 2
  • packages/core/src/parser.ts — track unknown flags with suggestions
  • packages/core/src/cli.ts — render unknown flag errors with suggestions
  • Tests for new threshold and flag suggestions

Depends on

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions