protected function getDevelopmentCommands() { if (!class_exists('TaskFile')) { return []; } $commands = []; $tasks = new TaskFile(); $runner = new Runner(); Config::setOutput(new ConsoleOutput()); $commandNames = array_filter(get_class_methods($tasks), function ($m) { return strpos($m, '__') === false; }); foreach ($commandNames as $commandName) { $command = $runner->createCommand(new TaskInfo('TaskFile', $commandName)); $command->setCode(function (InputInterface $input) use($tasks, $commandName) { // get passthru args $args = $input->getArguments(); array_shift($args); $args[] = $input->getOptions(); $res = call_user_func_array([$tasks, $commandName], $args); if (is_int($res)) { exit($res); } if (is_bool($res)) { exit($res ? 0 : 1); } if ($res instanceof Result) { exit($res->getExitCode()); } }); $commands[] = $command; } return $commands; }
public function execute($input = null) { register_shutdown_function(array($this, 'shutdown')); set_error_handler(array($this, 'handleError')); Config::setOutput(new ConsoleOutput()); $input = $this->prepareInput($input ? $input : $_SERVER['argv']); $app = new Application('Robo', self::VERSION); $app->addCommandsFromClass($this->roboClass, $this->passThroughArgs); $app->run($input); }
public function execute($input = null) { register_shutdown_function(array($this, 'shutdown')); Config::setOutput(new ConsoleOutput()); $input = $this->prepareInput($input ? $input : $_SERVER['argv']); if (!$this->loadRoboFile()) { $app = new Application('Robo', self::VERSION); $app->add(new Init('init')); $app->run(); return; } $app = $this->createApplication(self::ROBOCLASS); $app->run($input); }
public function execute($input = null) { register_shutdown_function(array($this, 'shutdown')); set_error_handler(array($this, 'handleError')); Config::setOutput(new ConsoleOutput()); $input = $this->prepareInput($input ? $input : $_SERVER['argv']); $app = new Application('Robo', self::VERSION); if (!$this->loadRoboFile()) { $this->yell("Robo is not initialized here. Please run `robo init` to create a new RoboFile", 40, 'yellow'); $app->addInitRoboFileCommand($this->roboFile, $this->roboClass); $app->run($input); return; } $app->addCommandsFromClass($this->roboClass, $this->passThroughArgs); $app->run($input); }
public function _after(\Codeception\TestCase $test) { \AspectMock\Test::clean(); Config::setOutput(new ConsoleOutput()); }
public function _after(\Codeception\TestCase $test) { $this->getModule('Filesystem')->deleteDir(codecept_data_dir() . 'sandbox'); Config::setOutput(new ConsoleOutput()); chdir(codecept_root_dir()); }
/** * @param null $input Input * @return int|void * @throws \Exception * * Run tg and return an error code */ public function run($input = null) { register_shutdown_function([$this, 'shutdown']); set_error_handler([$this, 'handleError']); if ($this->classCache->getCachePath() === null) { $this->classCache->setCachePath(__DIR__ . "/../.tg/"); } $hasCommandFile = $this->autoloadCommandFile(); $this->setupDevModes(); $this->input = $this->prepareInput($input ? $input : $_SERVER['argv']); //Load all our commands $commandLoader = new CommandLoader(); $this->loadLocalFile($commandLoader, $hasCommandFile); //Cwd project specific $this->loadCoreCommands($commandLoader); //Tg vendor and core if (!$this->coreDevMode) { //If we are developing in the core we dont want to load cwd vendors folder at all $this->loadLocalVendors($commandLoader); //Cwd vendor } if ($this->libDevMode) { //If we are developing a library we want to load the cwd source folder $this->loadLocalSrc($commandLoader); } //Set up the robo static config class :( Config::setInput($this->input); Config::setOutput($this->output); $this->app->setAutoExit(false); return $this->app->run($this->input, $this->output); }
/** * @param SymfonyConsole $app * @param string $className */ protected function mergeTasks($app, $className) { $commandNames = array_filter(get_class_methods($className), function ($m) use($className) { $method = new \ReflectionMethod($className, $m); return !in_array($m, ['__construct']) && !$method->isStatic(); // Reject constructors and static methods. }); $passThrough = $this->passThroughArgs; foreach ($commandNames as $commandName) { $command = $this->createCommand(new TaskInfo($className, $commandName)); $command->setCode(function (InputInterface $input, OutputInterface $output) use($className, $commandName, $passThrough) { // get passthru args $args = $input->getArguments(); array_shift($args); if ($passThrough) { $args[key(array_slice($args, -1, 1, true))] = $passThrough; } $args[] = $input->getOptions(); // Robo Command classes can access the current output via Config::get('output') // This output may have been customized for a specific command, usually when being run internally with // output capture. Config::setOutput($output); $roboTasks = $this->injector->make($className); $res = call_user_func_array([$roboTasks, $commandName], $args); // Restore the setting to the main output stream. Config::setOutput($this->io->getOutput()); if (is_int($res)) { return $res; } if (is_bool($res)) { return $res ? 0 : 1; } if ($res instanceof Result) { return $res->getExitCode(); } return $res; }); $app->add($command); } }
/** * Resume output */ protected function restoreOutput() { ob_get_clean(); Config::setOutput($this->output); }