Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions features/runner.feature
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,23 @@ Feature: Runner WP-CLI
Did you mean 'meta'?
"""
And the return code should be 1

Scenario: Suggest 'wp term <command>' when an invalid taxonomy command is run
Given a WP install

When I try `wp category list`
Then STDERR should contain:
"""
Did you mean 'wp term <command>'?
"""
And the return code should be 1

Scenario: Suggest 'wp post <command>' when an invalid post type command is run
Given a WP install

When I try `wp page create`
Then STDERR should contain:
"""
Did you mean 'wp post --post_type=page <command>'?
"""
And the return code should be 1
10 changes: 10 additions & 0 deletions php/WP_CLI/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,16 @@

$suggestion = $this->get_subcommand_suggestion( $full_name, $command );

// If the functions are available, it means WordPress is available
// and has already been loaded.
if ( function_exists( '\taxonomy_exists' ) ) {
if ( \taxonomy_exists( $cmd_path[0] ) ) {
$suggestion = 'wp term <command>';
} elseif ( \post_type_exists( $cmd_path[0] ) ) {
$suggestion = "wp post --post_type={$cmd_path[0]} <command>";

Check warning on line 405 in php/WP_CLI/Runner.php

View check run for this annotation

Codecov / codecov/patch

php/WP_CLI/Runner.php#L401-L405

Added lines #L401 - L405 were not covered by tests
}
}

return sprintf(
"'%s' is not a registered wp command. See 'wp help' for available commands.%s",
$full_name,
Expand Down