Handle exiting in error state on help & give suggestions.#4266
Handle exiting in error state on help & give suggestions.#4266danielbachhuber merged 11 commits intomasterfrom
Conversation
php/WP_CLI/Runner.php
Outdated
| ) ) { | ||
| $this->auto_check_update(); | ||
| $this->_run_command(); | ||
| // $this->auto_check_update(); // Disable for now? If it hits the cache threshold and determines to update it exits with no recourse for the user. |
There was a problem hiding this comment.
Let's keep $this->auto_check_update() in please, until we discuss further. This is WP-CLI's auto-update mechanism. It's non-trivial to disable it, particularly given we're so close to a release date.
php/WP_CLI/Runner.php
Outdated
| } | ||
|
|
||
| private function _run_command() { | ||
| private function _run_command( $exiting = true ) { |
There was a problem hiding this comment.
This seems like ambiguous behavior. Is there a better way to implement it?
There was a problem hiding this comment.
I'll remove the arg and rename the method _run_command_and_exit() and have the case after the 1st help attempt just use run_command( args...).
|
Generally, this pull request probably needs some discussion before further development. I'd be hesitant to land something like this without detailed conversation because it's a critical execution path and only has good, but not great, test coverage. |
php/WP_CLI/Runner.php
Outdated
| if ( is_string( $possible_suggestion ) ) { | ||
| WP_CLI::error( $possible_suggestion ); | ||
| } | ||
| // Should never happen. |
There was a problem hiding this comment.
How can we get to 100% confidence?
There was a problem hiding this comment.
Well if it does find the command then it doesn't return...if it doesn't then it does...then find_command_to_run() runs the same loop as find_command_to_help() so it will fail too and return a suggestion...100%!
There was a problem hiding this comment.
Ok, then we can remove the nonsensical error message.
There was a problem hiding this comment.
Removed amazingly amusing error message and now Help_Command uses Runner::find_command_to_run() so should be 100% confident.
| if ( function_exists( 'add_filter' ) ) { | ||
| $command_string = implode( ' ', $args ); | ||
| \WP_CLI::error( sprintf( "'%s' is not a registered wp command.", $command_string ) ); | ||
| } |
There was a problem hiding this comment.
Because it's a poor relation of what find_command_to_run() is doing...
There was a problem hiding this comment.
Can you clarify in greater detail? I'm hesitant to remove this without a clear articulation of what this was doing before and why removing it won't cause unintended consequences.
There was a problem hiding this comment.
I've changed it now to use Runner::find_command_to_help() to address #4266 (comment) fully, and removed find_command_to_help() (previously Help_Command::find_subcommand()) altogether - I'll expand below as the review commenting is getting a bit messy.
|
Doesn't seem to be a Linux version of that - will come up with something... |
features/help.feature
Outdated
| And STDERR should be: | ||
| """ | ||
| Error: 'non-existent-command' is not a registered wp command. | ||
| Error: 'non-existent-command' is not a registered wp command. See 'wp help'. |
There was a problem hiding this comment.
What do you think about changing:
See 'wp help'.
To:
See 'wp help' for available commands.
I think it adds more clarity to the message.
features/help.feature
Outdated
| """ | ||
| Warning: This does not seem to be a WordPress install. | ||
| If the command 'non-existent-command' is in a plugin or theme, pass --path=`path/to/wordpress`. | ||
| Error: 'non-existent-command' is not a registered wp command. See 'wp help'. |
There was a problem hiding this comment.
If we definitely know this isn't a WordPress install, we don't need to include If the command 'non-existent-command' is in a plugin or theme, pass --path=path/to/wordpress
There was a problem hiding this comment.
Changed it to one line "No WordPress install found. If the command...".
The idea behind mentioning about plugin/theme is to address your comment #4265 (comment) where the command could be added in a plugin/theme.
| """ | ||
| And STDOUT should be empty | ||
|
|
||
| Scenario: Suggestions for command typos in help |
There was a problem hiding this comment.
Does this scenario need Given an empty directory ?
| """ | ||
| And STDOUT should be empty | ||
|
|
||
| Scenario: Suggestions for subcommand typos in help of specially treated commands |
There was a problem hiding this comment.
This seems to be missing a Given too.
php/WP_CLI/Runner.php
Outdated
| if ( is_string( $possible_suggestion ) ) { | ||
| WP_CLI::error( $possible_suggestion ); | ||
| } | ||
| // Should never happen. |
There was a problem hiding this comment.
Ok, then we can remove the nonsensical error message.
php/WP_CLI/Runner.php
Outdated
| // In case the operation fails, ensure the timestamp has been updated. | ||
| $cache->write( $cache_key, time() ); | ||
|
|
||
| // Ask before doing remote request. |
There was a problem hiding this comment.
Can you remove this, please, and open an issue to discuss changes to the update process before making them?
php/class-wp-cli.php
Outdated
| * @param string $question Question to display before the prompt. | ||
| * @param array $assoc_args Skips prompt if 'yes' is provided. | ||
| */ | ||
| public static function ask( $question, $assoc_args = array() ) { |
There was a problem hiding this comment.
This can be removed for now.
| if ( function_exists( 'add_filter' ) ) { | ||
| $command_string = implode( ' ', $args ); | ||
| \WP_CLI::error( sprintf( "'%s' is not a registered wp command.", $command_string ) ); | ||
| } |
There was a problem hiding this comment.
Can you clarify in greater detail? I'm hesitant to remove this without a clear articulation of what this was doing before and why removing it won't cause unintended consequences.
``` Loading composer repositories with package information Updating dependencies Package operations: 0 installs, 1 update, 0 removals - Updating composer/composer (1.4.3 => 1.5.0): Checking out 6f3310c762 Writing lock file Generating autoload files ```
…p, use find_command_to_run.
|
Here's a before/after screenshot of running this bash script https://gist.github.com/gitlost/e895eb50068aff4ca36a61de3f74a2e7 in the Re removing the code from |
|
Thanks @gitlost. We can land this and see if anything shakes out of the behavior changes. |
|
Thanks @danielbachhuber, actually was trying to come up with a proper less hand-waving explanation when I noticed that there's an issue with help if the WP install is partial, as tested for in "Help when WordPress is downloaded but not installed" in wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli-nightly.phar -nc -q && mv wp-cli-nightly.phar wp-nightly.phar && chmod +x wp-nightly.phar
rm -rf /tmp/pull_4266_wp_install
mkdir /tmp/pull_4266_wp_install
mysql --user=wp_cli_test --password=password1 --execute='DROP DATABASE IF EXISTS wp_cli_test;'
./wp-nightly.phar core download --path=/tmp/pull_4266_wp_install
./wp-nightly.phar config create --dbname=wp_cli_test --dbuser=wp_cli_test --dbpass=password1 --path=/tmp/pull_4266_wp_install
./wp-nightly.phar help core is-installed --path=/tmp/pull_4266_wp_install
./wp-nightly.phar help --path=/tmp/pull_4266_wp_installwhere the help commands give Which probably explains why I'll push a fix to a new PR which involves adding a special |
Add help_wp_die_handler. Remove special help treatment for config and db (#4266).

Issue #4265
Adds handling of help command errors on exiting, giving suggestions.
Removes the handling in the help command itself, as it's not best placed to deal with it. Also renames its
find_subcommand()method tofind_command_to_help()as it's very confusing when it's not aCompositeCommand.Disables for now the
auto_check_update(), as it presents the user with an odd experience when triggered. It's hard to know where to put it.