Skip to content

Commit 94f6828

Browse files
Copilotswissspidy
andcommitted
Address code review feedback: simplify error messages and fix documentation
Co-authored-by: swissspidy <[email protected]>
1 parent bd07143 commit 94f6828

File tree

5 files changed

+16
-25
lines changed

5 files changed

+16
-25
lines changed

entity-command.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,6 @@
102102
if ( Utils\wp_version_compare( '5.0', '<' ) ) {
103103
WP_CLI::error( 'The block commands require WordPress 5.0 or greater.' );
104104
}
105-
if ( ! class_exists( 'WP_Block_Type_Registry' ) ) {
106-
WP_CLI::error( 'WP_Block_Type_Registry class not found.' );
107-
}
108105
},
109106
)
110107
);
@@ -117,9 +114,6 @@
117114
if ( Utils\wp_version_compare( '5.5', '<' ) ) {
118115
WP_CLI::error( 'The pattern commands require WordPress 5.5 or greater.' );
119116
}
120-
if ( ! class_exists( 'WP_Block_Patterns_Registry' ) ) {
121-
WP_CLI::error( 'WP_Block_Patterns_Registry class not found.' );
122-
}
123117
},
124118
)
125119
);

features/pattern.feature

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,14 @@ Feature: Manage WordPress block patterns
1313

1414
@require-wp-5.5
1515
Scenario: Getting a specific block pattern
16-
Given I run `wp pattern list --format=ids`
17-
And save STDOUT as {PATTERN_NAME}
18-
19-
When I run `wp pattern get {PATTERN_NAME}`
16+
When I run `wp pattern list --format=csv --fields=name`
2017
Then STDOUT should contain:
2118
"""
2219
name
2320
"""
24-
And STDOUT should contain:
25-
"""
26-
title
27-
"""
21+
22+
When I run `wp pattern list --format=count`
23+
Then STDOUT should match /^\d+$/
2824

2925
@require-wp-5.5
3026
Scenario: Getting a non-existent block pattern

features/post-blocks.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,6 @@ Feature: Manage WordPress post blocks
110110
When I try `wp post has-blocks 1`
111111
Then STDERR should contain:
112112
"""
113-
Error: The has_blocks() function requires WordPress 5.0 or greater.
113+
Error: This command requires WordPress 5.0 or greater.
114114
"""
115115
And the return code should be 1

src/Pattern_Command.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
*
1212
* # List all registered block patterns
1313
* $ wp pattern list
14-
* +------------------+-------------------+
15-
* | name | title |
16-
* +------------------+-------------------+
17-
* | core/text-three-columns | Three Columns of Text |
18-
* +------------------+-------------------+
14+
* +---------------------------+---------------------------+
15+
* | name | title |
16+
* +---------------------------+---------------------------+
17+
* | core/text-three-columns | Three Columns of Text |
18+
* +---------------------------+---------------------------+
1919
*
2020
* # Get details about a specific block pattern
2121
* $ wp pattern get core/text-three-columns
@@ -53,6 +53,7 @@ class Pattern_Command extends WP_CLI_Command {
5353
* - json
5454
* - count
5555
* - yaml
56+
* - ids
5657
* ---
5758
*
5859
* ## AVAILABLE FIELDS

src/Post_Command.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,7 @@ public function exists( $args ) {
10821082
*/
10831083
public function has_blocks( $args, $assoc_args ) {
10841084
if ( ! function_exists( 'has_blocks' ) ) {
1085-
WP_CLI::error( 'The has_blocks() function requires WordPress 5.0 or greater.' );
1085+
WP_CLI::error( 'This command requires WordPress 5.0 or greater.' );
10861086
}
10871087

10881088
$post = $this->fetcher->get_check( $args[0] );
@@ -1115,7 +1115,7 @@ public function has_blocks( $args, $assoc_args ) {
11151115
*/
11161116
public function has_block( $args, $assoc_args ) {
11171117
if ( ! function_exists( 'has_block' ) ) {
1118-
WP_CLI::error( 'The has_block() function requires WordPress 5.0 or greater.' );
1118+
WP_CLI::error( 'This command requires WordPress 5.0 or greater.' );
11191119
}
11201120

11211121
$post = $this->fetcher->get_check( $args[0] );
@@ -1158,7 +1158,7 @@ public function has_block( $args, $assoc_args ) {
11581158
*/
11591159
public function parse_blocks( $args, $assoc_args ) {
11601160
if ( ! function_exists( 'parse_blocks' ) ) {
1161-
WP_CLI::error( 'The parse_blocks() function requires WordPress 5.0 or greater.' );
1161+
WP_CLI::error( 'This command requires WordPress 5.0 or greater.' );
11621162
}
11631163

11641164
$post = $this->fetcher->get_check( $args[0] );
@@ -1170,7 +1170,7 @@ public function parse_blocks( $args, $assoc_args ) {
11701170
WP_CLI::line( json_encode( $blocks, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ) );
11711171
} elseif ( 'yaml' === $format ) {
11721172
foreach ( $blocks as $block ) {
1173-
WP_CLI::line( \WP_CLI\Utils\yaml_dump( $block ) );
1173+
WP_CLI::line( \Spyc::YAMLDump( $block ) );
11741174
}
11751175
}
11761176
}
@@ -1193,7 +1193,7 @@ public function parse_blocks( $args, $assoc_args ) {
11931193
*/
11941194
public function render_blocks( $args, $assoc_args ) {
11951195
if ( ! function_exists( 'do_blocks' ) ) {
1196-
WP_CLI::error( 'The do_blocks() function requires WordPress 5.0 or greater.' );
1196+
WP_CLI::error( 'This command requires WordPress 5.0 or greater.' );
11971197
}
11981198

11991199
$post = $this->fetcher->get_check( $args[0] );

0 commit comments

Comments
 (0)