diff --git a/inc/composer/class-command.php b/inc/composer/class-command.php index eaf0ab99..ba5e82eb 100644 --- a/inc/composer/class-command.php +++ b/inc/composer/class-command.php @@ -71,10 +71,10 @@ protected function configure() { Open a shell: shell Database commands: - db Log into MySQL on the Database server - db sequel Generates an SPF file for Sequel Pro - db info Prints out Database connection details - db exec -- "" Run and output the result of a SQL query. + db Log into MySQL on the Database server + db sequel Generates an SPF file for Sequel Pro + db info Prints out Database connection details + db exec -- "" 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 @@ -679,7 +679,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( 'No query specified: pass a query via `db exec -- "sql query..."`' ); break; @@ -688,7 +695,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: // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled