예제 #1
0
 /**
  * @param ICommand $command
  */
 public function render(ICommand $command)
 {
     $arguments = $command->getArguments();
     if (count($arguments) === 0) {
         return;
     }
     $table = new TableWidget($this->input, $this->output);
     $table->setTitle("<header>Arguments:</header>");
     foreach ($arguments as $argument) {
         $name = $argument->getName();
         $description = $argument->getDescription();
         if ($argument->isRequired()) {
             if ($argument->isMultiple()) {
                 $name = "\\<{$name}...>";
             } else {
                 $name = "\\<{$name}>";
             }
         } else {
             if ($argument->isMultiple()) {
                 $name = "\\<{$name}... ?>";
             } else {
                 $name = "\\<{$name} ?>";
             }
         }
         $table->addRow("<keyword>{$name}</keyword>", $description);
     }
     $this->output->writeLine();
     $table->render();
 }
예제 #2
0
 /**
  * @param ICommand $command
  */
 public function render(ICommand $command)
 {
     $description = $command->getDescription();
     if ($description) {
         $this->output->writeLine("<keyword>{$description}</keyword>");
     }
 }
예제 #3
0
 /**
  * @param ICommand $command
  */
 public function render(ICommand $command)
 {
     $help = $command->getHelp();
     if ($help) {
         $this->output->writeLine();
         $this->output->writeLine('<header>Help:</header>');
         $this->output->writeLineIndented($help);
     }
 }
 /**
  * @param IInput $input
  * @param IOutput $output
  * @param IRouter $router
  */
 public function run(IInput $input, IOutput $output, IRouter $router)
 {
     $this->input = $input;
     $this->output = $output;
     $facts = $this->gatherFacts($router);
     $this->output->writeLine(" <header>Routes: </header>");
     if (count($facts) > 0) {
         $this->renderFacts($facts);
     } else {
         $this->output->writeLineIndented("There are no routes yet");
     }
 }
예제 #5
0
 /**
  * @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);
 }
예제 #6
0
 /**
  * @param ICommand $command
  */
 public function render(ICommand $command)
 {
     $name = $command->getName();
     $usage = "{$name} ";
     if (count($command->getArguments())) {
         $usage .= $this->getArgumentsUsage($command->getArguments());
     }
     if (count($command->getOptions())) {
         $usage .= ' ' . $this->getOptionsUsage($command->getOptions());
     }
     $usage = trim($usage);
     $this->output->writeLine();
     $this->output->writeLine("<header>Usage:</header>");
     $this->output->writeLineIndented("{$usage}");
 }
예제 #7
0
 /**
  * @param string $string
  * @param array $choices
  * @param bool $useChoiceKeysAsSelector
  *
  * @return mixed
  */
 public function choose($string, array $choices, $useChoiceKeysAsSelector = true)
 {
     $this->output->writeLine("<question>{$string}</question>");
     $choicesMap = [];
     foreach ($choices as $subject => $message) {
         if ($useChoiceKeysAsSelector) {
             $index = $subject;
         } else {
             $index = count($choicesMap) + 1;
         }
         $choicesMap[$index] = ['subject' => $subject, 'message' => $message];
     }
     foreach ($choicesMap as $index => $choice) {
         $message = array_get($choice, 'message');
         $this->output->writeLineIndented("[<yellow>{$index}</yellow>] {$message}");
     }
     $choice = null;
     while (true) {
         $this->output->writeIndented('Choice: ');
         $input = $this->input->readLine();
         if (array_has($choicesMap, $input)) {
             $choice = array_get(array_get($choicesMap, $input), 'subject');
             break;
         }
         if (!empty($input)) {
             $this->output->writeLineIndented('<yellow>Invalid choice</yellow>');
         }
     }
     return $choice;
 }
예제 #8
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;
     }
 }
 /**
  * @param IInput $input
  * @param IOutput $output
  * @param IConfig $config
  */
 public function run(IInput $input, IOutput $output, IConfig $config)
 {
     $this->input = $input;
     $this->output = $output;
     $config = $config->toArray();
     $search = $input->getArgument('search');
     $config = array_dot($config);
     ksort($config);
     if ($search !== null) {
         $config = $this->findConfig($config, $search);
     }
     $this->output->writeLine(" <header>Config:</header>");
     if (count($config)) {
         $this->renderConfig($config);
     } else {
         $output->writeLineIndented('No configuration found');
     }
 }
예제 #10
0
 /**
  * @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');
     }
 }
예제 #11
0
 /**
  * @param ICommand $command
  */
 public function render(ICommand $command)
 {
     $options = $command->getOptions();
     if (count($options) === 0) {
         return;
     }
     $table = new TableWidget($this->input, $this->output);
     $table->setTitle("<header>Options:</header>");
     foreach ($options 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();
 }
예제 #12
0
 /**
  * @param Exception $ex
  */
 public function render(Exception $ex)
 {
     $message = $ex->getMessage();
     $stackTrace = $ex->getTraceAsString();
     $class = get_class($ex);
     $file = $ex->getFile();
     $line = $ex->getLine();
     $this->output->writeLine("<error>{$message}</error>");
     $this->output->writeLine('', OutputVerbosity::DEBUG);
     $this->output->writeLine("<error>{$class}</error>", OutputVerbosity::DEBUG);
     $this->output->writeLine("<error>In {$file} on {$line}</error>", OutputVerbosity::DEBUG);
     $this->output->writeLine('', OutputVerbosity::DEBUG);
     $this->output->writeLine("<error>{$stackTrace}</error>", OutputVerbosity::DEBUG);
 }
예제 #13
0
 /**
  * Render table.
  */
 public function render()
 {
     if ($this->title) {
         $this->output->writeLine($this->title);
     }
     $rows = $this->formatRows($this->rows);
     $widths = $this->calculateColumnWidths($rows);
     foreach ($rows as $row) {
         $type = $row['type'];
         foreach ($row['cols'] as $colIndex => $col) {
             if ($type === '@row') {
                 $width = array_get($widths, $colIndex);
                 $colWidth = strlen($this->output->format($col, OutputFormat::PLAIN));
                 // if not last row
                 if (array_has($row['cols'], $colIndex + 1)) {
                     $col .= str_repeat(' ', $width - $colWidth);
                 }
             }
             $this->output->write($col);
         }
         $this->output->writeLine();
     }
 }
예제 #14
0
 function it_shows_version(IInput $input, IOutput $output, IConsole $console)
 {
     $input->getOption('--version')->willReturn(true);
     $output->writeLine(Argument::type('string'))->shouldBeCalled();
     $this->run($input, $output, $console);
 }