Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom mysql flags for db exec command #549

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions inc/composer/class-command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 -- "<query>" 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 -- <args> "<query>" Run and output the result of a SQL query, with options mysql args.
shadyvb marked this conversation as resolved.
Show resolved Hide resolved
SSL commands:
ssl Show status on generated SSL certificates
ssl install Installs and trusts Root Certificate Authority
Expand Down Expand Up @@ -679,7 +679,11 @@ protected function db( InputInterface $input, OutputInterface $output ) {

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Elsewhere in this file the comments are all on their own line before the code they're describing, rather than line-ending comments. I'd suggest maintaining "keep comments on their own line" for consistency with the existing style.

shadyvb marked this conversation as resolved.
Show resolved Hide resolved

if ( empty( $query ) ) {
$output->writeln( '<error>No query specified: pass a query via `db exec -- "sql query..."`</error>' );
break;
Expand All @@ -688,7 +692,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
Expand Down