Skip to content

[LTA] Add "Did you mean ... ?" to GENERATE_USAGEΒ #5741

Open
@habere-et-dispertire

Description

The Problem

sub MAIN ( :$foo!, :$bar! ) {
}
$ raku did-you-mean.raku --foo --bat
Usage:
  did-you-mean.raku --foo[=Any] --bar[=Any]

Expected Behavior

$ raku did-you-mean.raku --foo --bat
Usage:
  did-you-mean.raku --foo[=Any] --bar[=Any]

Unknown option  bat
Did you mean    bar ?

We could suggest something like this as we do with near routine matches on compile errors :

use Text::Levenshtein::Damerau;

sub GENERATE-USAGE ( &main, |capture ) {

    [~] &*GENERATE-USAGE( &main, |capture ),

    gather for capture.keys -> $arg {
        next if &MAIN.signature.params.map( *.usage-name ).any eq $arg;
        take sprintf "\n\nUnknown option\t%s\nDid you mean\t%s ?", $arg, $_
        if 1 == dld( $arg, $_ )
        for &MAIN.signature.params.map( *.usage-name ).grep: none capture.keys;
    }

}

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions