self::$logger = $logger;
}
+ /**
+ * Get the logger instance.
+ *
+ * @return object
+ */
+ static function get_logger() {
+ return self::$logger;
+ }
+
static function get_configurator() {
return self::$configurator;
}
* Display an error in the CLI and end with a newline
*
* @param string $message
- * @param string $label
*/
- static function error( $message, $label = 'Error' ) {
- if ( ! isset( self::get_runner()->assoc_args[ 'completions' ] ) ) {
- self::$logger->error( self::error_to_string( $message ), $label );
- }
-
- exit(1);
+ static function error( $message, $deprecated = null ) {
+ throw new \WP_CLI\Exceptions\GeneralError( $message );
}
/**
WP_CLI::init();
-WP_CLI::get_runner()->before_wp_load();
-
-// Load wp-config.php code, in the global scope
-eval( WP_CLI::get_runner()->get_wp_config_code() );
-
-// Simulate a /wp-admin/ page load
-$_SERVER['PHP_SELF'] = '/wp-admin/index.php';
-define( 'WP_ADMIN', true );
-define( 'WP_NETWORK_ADMIN', false );
-define( 'WP_USER_ADMIN', false );
-
-// Load Core, mu-plugins, plugins, themes etc.
-require WP_CLI_ROOT . '/php/wp-settings-cli.php';
-
-// Fix memory limit. See http://core.trac.wordpress.org/ticket/14889
-@ini_set( 'memory_limit', -1 );
-
-require ABSPATH . 'wp-admin/includes/admin.php';
-do_action( 'admin_init' );
-
-WP_CLI::get_runner()->after_wp_load();
+try {
+ WP_CLI::get_runner()->before_wp_load();
+
+ // Load wp-config.php code, in the global scope
+ eval( WP_CLI::get_runner()->get_wp_config_code() );
+
+ // Simulate a /wp-admin/ page load
+ $_SERVER['PHP_SELF'] = '/wp-admin/index.php';
+ define( 'WP_ADMIN', true );
+ define( 'WP_NETWORK_ADMIN', false );
+ define( 'WP_USER_ADMIN', false );
+
+ // Load Core, mu-plugins, plugins, themes etc.
+ require WP_CLI_ROOT . '/php/wp-settings-cli.php';
+
+ // Fix memory limit. See http://core.trac.wordpress.org/ticket/14889
+ @ini_set( 'memory_limit', -1 );
+
+ require ABSPATH . 'wp-admin/includes/admin.php';
+ do_action( 'admin_init' );
+
+ WP_CLI::get_runner()->after_wp_load();
+} catch ( \WP_CLI\Exceptions\GeneralError $e ) {
+ if ( !isset( WP_CLI::get_runner()->assoc_args[ 'completions' ] ) ) {
+ WP_CLI::get_logger()->error( WP_CLI::error_to_string( $e->getMessage() ), 'Error' );
+ }
+ exit(1);
+}