New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pre-built dictionary of "did you mean..." suggestions #4379

Closed
schlessera opened this Issue Sep 24, 2017 · 14 comments

Comments

4 participants
@schlessera
Member

schlessera commented Sep 24, 2017

For #3861 we built an algorithm that compares an invalid parameter to all possible parameters based on Levenshtein distance and makes suggestions if the Levenshtein distance is below or equal a set threshold (currently 2).

We still need to add a dictionary of pre-built "invalid parameter" => "suggestion" mappings so that we can provide meaningful suggestions that more drastically deviate from what was typed, without the need to bump the threshold higher. A too high threshold will show more meaningless suggestions.

The dictionary should just be an associative array that takes precedence over the calculated suggestion:

function get_suggestion( $target, array $options, $threshold = 2 ) {
   $suggestion_map = array(
      'dbpassword' => 'dbpass',
      // [...]
   );

   if ( array_key_exists( $target, $suggestion_map ) ) {
      return $suggestion_map[ $target ];
   }

   // [...]
}
@szepeviktor

This comment has been minimized.

Show comment
Hide comment
@szepeviktor

szepeviktor Sep 24, 2017

Contributor

How do git and drush do it?
Something like http://php.net/manual/en/function.levenshtein.php ?

Contributor

szepeviktor commented Sep 24, 2017

How do git and drush do it?
Something like http://php.net/manual/en/function.levenshtein.php ?

@szepeviktor

This comment has been minimized.

Show comment
Hide comment
@szepeviktor

This comment has been minimized.

Show comment
Hide comment
@szepeviktor

szepeviktor Sep 24, 2017

Contributor

Drush does not try to correct typos:

$ drush watchdog-shoe
The drush command 'watchdog-shoe' could not be found. 
Contributor

szepeviktor commented Sep 24, 2017

Drush does not try to correct typos:

$ drush watchdog-shoe
The drush command 'watchdog-shoe' could not be found. 
@szepeviktor

This comment has been minimized.

Show comment
Hide comment
@szepeviktor

szepeviktor Sep 24, 2017

Contributor

👍 for Levenshtein.

Contributor

szepeviktor commented Sep 24, 2017

👍 for Levenshtein.

@schlessera

This comment has been minimized.

Show comment
Hide comment
@schlessera

schlessera Sep 24, 2017

Member

@szepeviktor We are already using levenshtein():

$distance = levenshtein( $option, $target );

The issue above is for the cases where the distance would be so large that we cannot provide a meaningful threshold anymore. A high threshold just produces random suggestions.

Member

schlessera commented Sep 24, 2017

@szepeviktor We are already using levenshtein():

$distance = levenshtein( $option, $target );

The issue above is for the cases where the distance would be so large that we cannot provide a meaningful threshold anymore. A high threshold just produces random suggestions.

@szepeviktor

This comment has been minimized.

Show comment
Hide comment
@szepeviktor

szepeviktor Sep 24, 2017

Contributor

Thank you.
Nowadays I am not up-to-date with WP-CLI.

Contributor

szepeviktor commented Sep 24, 2017

Thank you.
Nowadays I am not up-to-date with WP-CLI.

@schlessera

This comment has been minimized.

Show comment
Hide comment
@schlessera

schlessera Sep 24, 2017

Member

Ha, no worries. See it as a confirmation that we all found your idea worthwhile! ;)

Member

schlessera commented Sep 24, 2017

Ha, no worries. See it as a confirmation that we all found your idea worthwhile! ;)

@danielbachhuber

This comment has been minimized.

Show comment
Hide comment
@danielbachhuber

danielbachhuber Sep 26, 2017

Member

We still need to add a dictionary of pre-built "invalid parameter" => "suggestion" mappings so that we can provide meaningful suggestions that more drastically deviate from what was typed, without the need to bump the threshold higher. A too high threshold will show more meaningless suggestions.

How should we produce this dictionary?

Member

danielbachhuber commented Sep 26, 2017

We still need to add a dictionary of pre-built "invalid parameter" => "suggestion" mappings so that we can provide meaningful suggestions that more drastically deviate from what was typed, without the need to bump the threshold higher. A too high threshold will show more meaningless suggestions.

How should we produce this dictionary?

@schlessera

This comment has been minimized.

Show comment
Hide comment
@schlessera

schlessera Sep 26, 2017

Member

Right now, we have 1 entry:

'dbpassword' => 'dbpass'

I'd suggest starting with that one and adding whenever we find a type/wrong parameter name that we think should produce a meaningful suggestion but doesn't.

Member

schlessera commented Sep 26, 2017

Right now, we have 1 entry:

'dbpassword' => 'dbpass'

I'd suggest starting with that one and adding whenever we find a type/wrong parameter name that we think should produce a meaningful suggestion but doesn't.

@danielbachhuber

This comment has been minimized.

Show comment
Hide comment
@danielbachhuber

danielbachhuber Sep 26, 2017

Member

I'd suggest starting with that one and adding whenever we find a type/wrong parameter name that we think should produce a meaningful suggestion but doesn't.

Sounds good. To address this issue fully, it'd be great to have someone spend ~30 minutes reviewing arguments for all bundled WP-CLI commands and produce a list of a dozen mapping suggestions we can start with.

Member

danielbachhuber commented Sep 26, 2017

I'd suggest starting with that one and adding whenever we find a type/wrong parameter name that we think should produce a meaningful suggestion but doesn't.

Sounds good. To address this issue fully, it'd be great to have someone spend ~30 minutes reviewing arguments for all bundled WP-CLI commands and produce a list of a dozen mapping suggestions we can start with.

@n8finch

This comment has been minimized.

Show comment
Hide comment
@n8finch

n8finch Sep 29, 2017

Contributor

Sounds good. To address this issue fully, it'd be great to have someone spend ~30 minutes reviewing arguments for all bundled WP-CLI commands and produce a list of a dozen mapping suggestions we can start with.

Just to clarify, are you looking for parameters only, or subcommands as well?

For example:

  • Subcommand should be: wp cli check-update
  • Array could include: 'check' => 'check-update' , 'check update' => 'check-update'
  • Errors received:
Error: 'check' is not a registered subcommand of 'cli'. See 'wp help cli' for available subcommands.

Or

  • Command with parameters should be: wp core download --locale=en --version=4.2
  • Array could include: 'language' => 'local' , 'v' => 'version'
    Error received:
Error: Parameter errors: unknown --language parameter
Error: Parameter errors: unknown --v parameter

If those are the droids--I mean arrays--you're looking for, I'd be happy to take this on and get the associative array rolling. 🤓

Contributor

n8finch commented Sep 29, 2017

Sounds good. To address this issue fully, it'd be great to have someone spend ~30 minutes reviewing arguments for all bundled WP-CLI commands and produce a list of a dozen mapping suggestions we can start with.

Just to clarify, are you looking for parameters only, or subcommands as well?

For example:

  • Subcommand should be: wp cli check-update
  • Array could include: 'check' => 'check-update' , 'check update' => 'check-update'
  • Errors received:
Error: 'check' is not a registered subcommand of 'cli'. See 'wp help cli' for available subcommands.

Or

  • Command with parameters should be: wp core download --locale=en --version=4.2
  • Array could include: 'language' => 'local' , 'v' => 'version'
    Error received:
Error: Parameter errors: unknown --language parameter
Error: Parameter errors: unknown --v parameter

If those are the droids--I mean arrays--you're looking for, I'd be happy to take this on and get the associative array rolling. 🤓

@danielbachhuber

This comment has been minimized.

Show comment
Hide comment
@danielbachhuber

danielbachhuber Sep 29, 2017

Member

Just to clarify, are you looking for parameters only, or subcommands as well?

Your latter example for now — command parameters.

Member

danielbachhuber commented Sep 29, 2017

Just to clarify, are you looking for parameters only, or subcommands as well?

Your latter example for now — command parameters.

@n8finch

This comment has been minimized.

Show comment
Hide comment
@n8finch

n8finch Sep 29, 2017

Contributor

Great! I'll get on that.

Contributor

n8finch commented Sep 29, 2017

Great! I'll get on that.

@schlessera

This comment has been minimized.

Show comment
Hide comment
@schlessera

schlessera Oct 5, 2017

Member

Fixed with #4392

Member

schlessera commented Oct 5, 2017

Fixed with #4392

@schlessera schlessera closed this Oct 5, 2017

@schlessera schlessera added this to the 1.4.0 milestone Oct 5, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment