Beispiel #1
0
 function it_runs_help_for_command(IInput $input, IOutput $output, IConsole $console)
 {
     $input->hasOption('--help')->willReturn(true);
     $input->getArgument('args')->willReturn(['name']);
     $console->parseString('help name')->shouldBeCalled();
     $this->run($input, $output, $console);
 }
Beispiel #2
0
 /**
  * @param IInput $input
  * @param IConsole $console
  *
  * @return ICommand
  * @throws AmbiguousCommandException
  * @throws CommandNotFoundException
  */
 protected function findCommand(IInput $input, IConsole $console)
 {
     if ($input->hasArgument('command')) {
         $matcher = new ArgumentsMatcher(new ArgumentsParser());
         return $matcher->findCommand($console->getCommands(), $input->getArgument('command'));
     }
     return $input->getCommand();
 }
Beispiel #3
0
 /**
  * @param $string
  */
 public function handleArgsString($string)
 {
     $option = $this->createEnvOption();
     $option->parseString($string);
     $this->detectEnvFromOption($option);
     $this->start();
     $this->console->parseString($string);
 }
Beispiel #4
0
 /**
  * @param IInput $input
  * @param IOutput $output
  * @param IConsole $console
  *
  * @return bool
  */
 public function run(IInput $input, IOutput $output, IConsole $console)
 {
     if ($input->getOption('--version')) {
         $version = $console->getVersion();
         $output->writeLine("<keyword>Application version {$version}</keyword>");
         return false;
     }
 }
 function it_renders_without_Commands(IConsole $console)
 {
     $console->getCommands()->willReturn([]);
     $input = new Input();
     $output = new Output();
     $output->setEnableBuffering(true);
     $this->beConstructedWith($input, $output);
     $this->render($console);
 }
Beispiel #6
0
 /**
  * @param IInput $input
  * @param IOutput $output
  * @param IConsole $console
  *
  * @return bool
  */
 public function run(IInput $input, IOutput $output, IConsole $console)
 {
     if ($input->hasOption('--help')) {
         $args = $input->getArgument('args');
         $subject = array_shift($args);
         $console->parseString("help {$subject}");
         return false;
     }
 }
Beispiel #7
0
 function it_runs(IInput $input, IConsole $console)
 {
     $console->getCommands()->willReturn([new Command('test')]);
     $input->hasArgument('command')->willReturn(true);
     $input->getArgument('command')->willReturn('test');
     $output = new Output();
     $output->setEnableBuffering(true);
     $this->run($input, $output, $console);
 }
 /**
  * @param IConsole $console
  */
 public function render(IConsole $console)
 {
     $title = $console->getTitle();
     $description = $console->getDescription();
     if ($title === null) {
         $title = 'Console application';
     }
     if ($description === null) {
         $description = 'A unified console for all kinds of commands';
     }
     $this->output->writeLine("<keyword>{$title}</keyword>");
     $this->output->writeLine($description);
 }
 /**
  * @param IConsole $console
  */
 public function render(IConsole $console)
 {
     $facts = $this->gatherFacts($console->getCommands());
     if (count($facts) > 0) {
         $table = new TableWidget($this->input, $this->output);
         $table->setTitle("<header>Available commands:</header>");
         $headers = [];
         foreach ($facts as $name => $description) {
             if (stripos($name, ':') !== false) {
                 $header = array_first(explode(':', $name));
                 if (!array_contains($headers, $header)) {
                     $headers[] = $header;
                     $table->addSection("<header>{$header}</header>");
                 }
             }
             $table->addRow("<keyword>{$name}</keyword>", $description);
         }
         $this->output->writeLine();
         $table->render();
     } else {
         $this->output->writeLineIndented('There are no commands yet');
     }
 }
Beispiel #10
0
 /**
  * Render options.
  */
 public function render()
 {
     $table = new TableWidget($this->input, $this->output);
     $table->setTitle("<header>Global options:</header>");
     foreach ($this->console->getCommands() as $command) {
         if ($command->isGlobal()) {
             foreach ($command->getOptions() as $option) {
                 $name = $option->getName();
                 $alias = '   ';
                 if ($option->getAlias()) {
                     $alias = $option->getAlias();
                     if ($option->isIncremental()) {
                         $alias = s('-:a|:a:a|:a:a:a', [':a' => substr($alias, 1)]);
                     }
                     $alias .= ',';
                 }
                 $table->addRow("<keyword>{$alias} {$name}</keyword>", $option->getDescription());
             }
         }
     }
     $this->output->writeLine();
     $table->render();
 }
 /**
  * @param IInput $input
  * @param IOutput $output
  * @param IConsole $console
  *
  * @return bool
  */
 public function run(IInput $input, IOutput $output, IConsole $console)
 {
     if ($input->getOption('--passthrough')) {
         $console->setCatchErrors(false);
     }
 }
 function it_disables_error_catching(IInput $input, IOutput $output, IConsole $console)
 {
     $console->setCatchErrors(false)->shouldBeCalled();
     $input->getOption('--passthrough')->willReturn(true);
     $this->run($input, $output, $console);
 }