/** * Execute WP-CLI against configuration for a given environment * * <core> * * <download> * * * @when before_wp_load */ public function __invoke($args, $assoc_args) { global $argv; try { $environment = new \ViewOne\WPCLIEnvironment\Environment(); $environment->run($argv[1]); } catch (Exception $e) { \WP_CLI::error($e->getMessage()); } $command = \ViewOne\WPCLIEnvironment\Command::getCommand($args, $assoc_args); WP_CLI::launch($command); }
/** * Generate command class based on $args, $assocParams and $params * and put content in Command.php file in global cache wp-cli path. * * @return void */ public static function generateCommandClass() { $args = \ViewOne\WPCLIEnvironment\Command::getArguments(); $assocParams = \ViewOne\WPCLIEnvironment\Command::getAssocParameters(); $params = \ViewOne\WPCLIEnvironment\Command::getParameters(); $moutstache = new \Mustache_Engine(); $dir = self::getCachePath(); if (!file_exists($dir . '/wp-cli-environment')) { mkdir($dir . '/wp-cli-environment', 0777, true); } $template = file_get_contents(__DIR__ . '/../../../template/command.mustache'); $variables = array('args' => $args, 'assoc_params' => $assocParams, 'params' => $params); $class = $moutstache->render($template, $variables); file_put_contents($dir . '/wp-cli-environment/Command.php', $class); }