}
/**
- * Exports the database using mysqldump. Accepts all of mysqldump's arguments.
+ * Exports the database to a file or to STDOUT.
*
- * @alias dump
+ * ## OPTIONS
+ *
+ * [<file>]
+ * : The name of the SQL file to export. If '-', then outputs to STDOUT. If omitted, it will be '{dbname}.sql'.
+ *
++ * [--<field>=<value>]
++ * : Extra arguments to pass to mysqldump
++ *
++ * ## EXAMPLES
+ *
- * @synopsis [<file>] [--extended-insert] [--skip-comments] [--<field>=<value>]
++ * wp db dump --add-drop-table
++ *
+ * @alias dump
*/
function export( $args, $assoc_args ) {
- $assoc_args['result-file'] = $this->get_file_name( $args );
+ $result_file = $this->get_file_name( $args );
+ $stdout = ( '-' === $result_file );
+
- $cmd_args = array();
+ if ( ! $stdout ) {
- $cmd_args['result-file'] = $result_file;
++ $assoc_args['result-file'] = $result_file;
+ }
- self::run( Utils\esc_cmd( 'mysqldump %s', DB_NAME ), $cmd_args );
+
+ self::run( Utils\esc_cmd( 'mysqldump %s', DB_NAME ), $assoc_args );
- WP_CLI::success( sprintf( 'Exported to %s', $assoc_args['result-file'] ) );
+ if ( ! $stdout ) {
+ WP_CLI::success( sprintf( 'Exported to %s', $result_file ) );
+ }
}
/**