@@ -19,7 +19,7 @@ class WP_Stream_WP_CLI_Command extends WP_CLI_Command {
19
19
* : One or more args to pass to wp_stream_query.
20
20
*
21
21
* [--format=<format>]
22
- * : Accepted values: table, json, csv . Default: table
22
+ * : Accepted values: table, json, json_pretty . Default: table
23
23
*
24
24
* ## AVAILABLE FIELDS TO QUERY
25
25
*
@@ -106,13 +106,29 @@ public function query( $args, $assoc_args ) {
106
106
}
107
107
108
108
foreach ( $ assoc_args as $ key => $ value ) {
109
+ if ( 'format ' === $ key ) {
110
+ continue ;
111
+ }
112
+
109
113
$ query_args [ $ key ] = $ value ;
110
114
}
111
115
112
116
$ query_args ['fields ' ] = implode ( ', ' , $ fields );
113
117
114
118
$ records = wp_stream_query ( $ query_args );
115
119
120
+ if ( isset ( $ assoc_args ['format ' ] ) ) {
121
+ if ( 'json ' === $ assoc_args ['format ' ] ) {
122
+ $ output = json_encode ( $ records );
123
+ } elseif ( 'json_pretty ' === $ assoc_args ['format ' ] ) {
124
+ $ output = json_encode ( $ records , JSON_PRETTY_PRINT );
125
+ }
126
+
127
+ echo $ output . "\n" ;
128
+
129
+ return ;
130
+ }
131
+
116
132
// Make structure Formatter compatible
117
133
foreach ( (array ) $ records as $ key => $ record ) {
118
134
$ formatted_records [ $ key ] = array ();
@@ -133,7 +149,7 @@ public function query( $args, $assoc_args ) {
133
149
$ formatter ->display_items ( $ formatted_records );
134
150
135
151
if ( 0 === ( $ found = count ( $ records ) ) ) {
136
- WP_CLI ::line ( 'No records found. ' );
152
+ WP_CLI ::line ( __ ( 'No records found. ' , ' stream ' ) );
137
153
} else {
138
154
WP_CLI ::line ( sprintf ( _n ( '1 record found. ' , '%s records found. ' , $ found , 'stream ' ), number_format ( $ found ) ) );
139
155
}
0 commit comments