Skip to content

Commit b3b9839

Browse files
authored
Merge pull request #9 from Automattic/add/support-for-json-format
Add support for JSON format for table list
2 parents 072503e + 54cae59 commit b3b9839

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

‎features/sqlite_tables.feature‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,11 @@ Feature: WP-CLI SQLite Tables Command
3232
"""
3333
wp_users,wp_usermeta,wp_termmeta,wp_terms,wp_term_taxonomy,wp_term_relationships,wp_commentmeta,wp_comments,wp_links,wp_options,wp_postmeta,wp_posts
3434
"""
35+
36+
@require-sqlite
37+
Scenario: Successfully list the tables in the SQLite database in a CSV format
38+
When I run `wp sqlite tables --format=json`
39+
Then STDOUT should contain:
40+
"""
41+
["wp_users","wp_usermeta","wp_termmeta","wp_terms","wp_term_taxonomy","wp_term_relationships","wp_commentmeta","wp_comments","wp_links","wp_options","wp_postmeta","wp_posts"]
42+
"""

‎src/Tables.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public function run( $assoc_args = [] ) {
4949

5050
if ( 'csv' === $format ) {
5151
WP_CLI::line( implode( ',', $tables ) );
52+
} elseif ( 'json' === $format ) {
53+
WP_CLI::line( json_encode( array_values( $tables ) ) );
5254
} else {
5355
foreach ( $tables as $table ) {
5456
WP_CLI::line( $table );

0 commit comments

Comments
 (0)