Skip to content

Commit

Permalink
Rename and reorder the columns
Browse files Browse the repository at this point in the history
  • Loading branch information
2ndkauboy committed Apr 26, 2024
1 parent 1c9b2e8 commit 9e9ec17
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/DB_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -1484,12 +1484,16 @@ public function search( $args, $assoc_args ) {

if ( $format ) {
$search_results[] = [
'table' => $table,
'column' => $column,
'key' => $primary_key,
'value' => $result->$primary_key,
'table' => $table,
'column' => $column,
// Remove the colors for the format output.
'match' => str_replace( [ $colors['match'][0], $colors['match'][1] ], [ '', '' ], $col_val ),
'match' => str_replace(
[ $colors['match'][0], $colors['match'][1] ],
[ '','' ],
$col_val
),
'primary_key_name' => $primary_key,
'primary_key_value' => $result->$primary_key,
];
} else {
WP_CLI::log( $matches_only ? $col_val : ( $one_line ? "{$table_column_val}:{$pk_val}{$col_val}" : "{$pk_val}{$col_val}" ) );
Expand All @@ -1504,7 +1508,7 @@ public function search( $args, $assoc_args ) {
$formatter_args = [
'format' => $format,
];
$formatter_fields = [ 'table', 'column', 'key', 'value', 'match' ];
$formatter_fields = [ 'table', 'column', 'match', 'primary_key_name', 'primary_key_value' ];

if ( $fields ) {
$fields = explode( ',', $assoc_args['fields'] );
Expand All @@ -1515,7 +1519,7 @@ public function search( $args, $assoc_args ) {
if ( count( $tables ) > 1 ) {
WP_CLI::error( 'The "ids" format can only be used for a single table.' );
}
$search_results = array_column( $search_results, 'value' );
$search_results = array_column( $search_results, 'primary_key_value' );
}

$formatter = new Formatter( $formatter_args, $formatter_fields );
Expand Down

0 comments on commit 9e9ec17

Please sign in to comment.