Beispiel #1
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");
     }
 }
Beispiel #3
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}");
 }
Beispiel #4
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;
 }
 /**
  * @param array $config
  */
 private function renderConfig(array $config)
 {
     foreach ($config as $key => $value) {
         if ($value === true) {
             $value = 'true';
         } else {
             if ($value === false) {
                 $value = 'false';
             }
         }
         $this->output->writeLineIndented("<green>{$key}</green>: {$value}");
     }
 }
 /**
  * @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');
     }
 }