diff --git a/features/sqlite_tables.feature b/features/sqlite_tables.feature index 201519f..e3527f6 100644 --- a/features/sqlite_tables.feature +++ b/features/sqlite_tables.feature @@ -32,3 +32,11 @@ Feature: WP-CLI SQLite Tables Command """ 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 """ + + @require-sqlite + Scenario: Successfully list the tables in the SQLite database in a CSV format + When I run `wp sqlite tables --format=json` + Then STDOUT should contain: + """ + ["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"] + """ diff --git a/src/Tables.php b/src/Tables.php index 5dbd283..4af576f 100644 --- a/src/Tables.php +++ b/src/Tables.php @@ -49,6 +49,8 @@ public function run( $assoc_args = [] ) { if ( 'csv' === $format ) { WP_CLI::line( implode( ',', $tables ) ); + } elseif ( 'json' === $format ) { + WP_CLI::line( json_encode( array_values( $tables ) ) ); } else { foreach ( $tables as $table ) { WP_CLI::line( $table );