Skip to content

Commit

Permalink
Merge pull request #549 from humanmade/548/allow-custom-mysql-flags
Browse files Browse the repository at this point in the history
Allow custom mysql flags for db exec command
  • Loading branch information
mikelittle authored Jan 15, 2025
2 parents 428f83e + 29e6001 commit 5912f14
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions inc/composer/class-command.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected function configure() {
db (sequel|spf) Opens Sequel Pro/Sequel Ace with the database connection
db (tableplus|tbp) Opens TablePlus with the database connection
db info Prints out Database connection details
db exec -- "<query>" Run and output the result of a SQL query.
db exec -- <args> "<query>" Run and output the result of a SQL query, with optional mysql args.
SSL commands:
ssl Show status on generated SSL certificates
ssl install Installs and trusts Root Certificate Authority
Expand Down Expand Up @@ -719,7 +719,14 @@ protected function db( InputInterface $input, OutputInterface $output ) {
break;

case 'exec':
$query = $input->getArgument( 'options' )[1] ?? null;
$options = $input->getArgument( 'options' ) ?? [];
// Remove the subcommand, we don't need it.
array_shift( $options );
// The query is always the last option.
$query = array_pop( $options ) ?: null;
// Implode all optional options.
$args = count( $options ) > 0 ? implode( ' ', $options ) : '';

if ( empty( $query ) ) {
$output->writeln( '<error>No query specified: pass a query via `db exec -- "sql query..."`</error>' );
break;
Expand All @@ -728,7 +735,7 @@ protected function db( InputInterface $input, OutputInterface $output ) {
$query = "$query;";
}
// phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled
passthru( "$base_command mysql --database=wordpress --user=root -e \"$query\"", $return_val );
passthru( "$base_command mysql --database=wordpress --user=root $args -e \"$query\"", $return_val );
break;

case null:
Expand Down

0 comments on commit 5912f14

Please sign in to comment.