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;
 }
Example #2
0
 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);
 }
Example #3
0
 /**
  * @inheritdoc
  * @throws TerminusException
  */
 public function get($key, $defaultOverride = null)
 {
     if (!$this->configured) {
         $this->configure();
         $this->configured = true;
     }
     if (!isset($this->config[$key])) {
         throw new TerminusException('No configuration setting for {key} found.', compact('key'));
     }
     return parent::get($key);
 }
Example #4
0
 public function addInitRoboFileCommand($roboFile, $roboClass)
 {
     $createRoboFile = new Command('init');
     $createRoboFile->setDescription("Intitalizes basic RoboFile in current dir");
     $createRoboFile->setCode(function () use($roboClass, $roboFile) {
         $output = Config::get('output');
         $output->writeln("<comment>  ~~~ Welcome to Robo! ~~~~ </comment>");
         $output->writeln("<comment>  " . $roboFile . " will be created in current dir </comment>");
         file_put_contents($roboFile, '<?php' . "\n/**" . "\n * This is project's console commands configuration for Robo task runner." . "\n *" . "\n * @see http://robo.li/" . "\n */" . "\nclass " . $roboClass . " extends \\Robo\\Tasks\n{\n    // define public methods as commands\n}");
         $output->writeln("<comment>  Edit RoboFile.php to add your commands! </comment>");
     });
     $this->add($createRoboFile);
 }
Example #5
0
 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);
 }
Example #6
0
File: Runner.php Project: ak4n/Robo
 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);
 }
Example #7
0
 public function _after(\Codeception\TestCase $test)
 {
     \AspectMock\Test::clean();
     Config::setOutput(new ConsoleOutput());
 }
Example #8
0
File: Robo.php Project: jjok/Robo
 /**
  * Initialize a container with all of the default Robo services.
  * IMPORTANT:  after calling this method, clients MUST call:
  *
  * $dispatcher = $container->get('eventDispatcher');
  * $app->setDispatcher($dispatcher);
  *
  * Any modification to the container should be done prior to fetching
  * objects from it.
  *
  * It is recommended to use \Robo::createDefaultContainer()
  * instead, which does all required setup for the caller, but has
  * the limitation that the container it creates can only be
  * extended, not modified.
  *
  * @param \League\Container\ContainerInterface $container
  * @param \Symfony\Component\Console\Application $app
  * @param \Robo\Config $config
  * @param null|\Symfony\Component\Console\Input\InputInterface $input
  * @param null|\Symfony\Component\Console\Output\OutputInterface $output
  */
 public static function configureContainer(ContainerInterface $container, SymfonyApplication $app, Config $config, $input = null, $output = null)
 {
     // Self-referential container refernce for the inflector
     $container->add('container', $container);
     static::setContainer($container);
     // Create default input and output objects if they were not provided
     if (!$input) {
         $input = new StringInput('');
     }
     if (!$output) {
         $output = new \Symfony\Component\Console\Output\ConsoleOutput();
     }
     $config->setDecorated($output->isDecorated());
     $container->share('application', $app);
     $container->share('config', $config);
     $container->share('input', $input);
     $container->share('output', $output);
     // Register logging and related services.
     $container->share('logStyler', \Robo\Log\RoboLogStyle::class);
     $container->share('logger', \Robo\Log\RoboLogger::class)->withArgument('output')->withMethodCall('setLogOutputStyler', ['logStyler']);
     $container->add('progressBar', \Symfony\Component\Console\Helper\ProgressBar::class)->withArgument('output');
     $container->share('progressIndicator', \Robo\Common\ProgressIndicator::class)->withArgument('progressBar')->withArgument('output');
     $container->share('resultPrinter', \Robo\Log\ResultPrinter::class);
     $container->add('simulator', \Robo\Task\Simulator::class);
     $container->share('globalOptionsEventListener', \Robo\GlobalOptionsEventListener::class);
     $container->share('collectionProcessHook', \Robo\Collection\CollectionProcessHook::class);
     $container->share('hookManager', \Consolidation\AnnotatedCommand\Hooks\HookManager::class)->withMethodCall('addResultProcessor', ['collectionProcessHook', '*']);
     $container->share('alterOptionsCommandEvent', \Consolidation\AnnotatedCommand\Options\AlterOptionsCommandEvent::class)->withArgument('application');
     $container->share('eventDispatcher', \Symfony\Component\EventDispatcher\EventDispatcher::class)->withMethodCall('addSubscriber', ['globalOptionsEventListener'])->withMethodCall('addSubscriber', ['alterOptionsCommandEvent'])->withMethodCall('addSubscriber', ['hookManager']);
     $container->share('formatterManager', \Consolidation\OutputFormatters\FormatterManager::class)->withMethodCall('addDefaultFormatters', [])->withMethodCall('addDefaultSimplifiers', []);
     $container->share('commandProcessor', \Consolidation\AnnotatedCommand\CommandProcessor::class)->withArgument('hookManager')->withMethodCall('setFormatterManager', ['formatterManager'])->withMethodCall('setDisplayErrorFunction', [function ($output, $message) use($container) {
         $logger = $container->get('logger');
         $logger->error($message);
     }]);
     $container->share('commandFactory', \Consolidation\AnnotatedCommand\AnnotatedCommandFactory::class)->withMethodCall('setCommandProcessor', ['commandProcessor']);
     $container->add('collection', \Robo\Collection\Collection::class);
     $container->add('collectionBuilder', \Robo\Collection\CollectionBuilder::class);
     static::addInflectors($container);
     // Make sure the application is appropriately initialized.
     $app->setAutoExit(false);
 }
Example #9
0
 public function _after(\Codeception\TestCase $test)
 {
     $this->getModule('Filesystem')->deleteDir(codecept_data_dir() . 'sandbox');
     Config::setOutput(new ConsoleOutput());
     chdir(codecept_root_dir());
 }
Example #10
0
 /**
  * @return OutputInterface
  */
 protected function getOutput()
 {
     return Config::get('output', new NullOutput());
 }
Example #11
0
File: Tg.php Project: twhiston/tg
 /**
  * @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);
     }
 }
Example #13
0
File: IO.php Project: zondor/Robo
 /**
  * @return InputInterface
  */
 protected function getInput()
 {
     return Config::get('input', new ArgvInput());
 }
Example #14
0
 protected function getConfigValue($key, $default = null)
 {
     return Config::get(static::getClassKey($key), $default);
 }
Example #15
0
 /**
  * Resume output
  */
 protected function restoreOutput()
 {
     ob_get_clean();
     Config::setOutput($this->output);
 }