/**
  * @param IInput $input
  * @param IOutput $output
  */
 public function run(IInput $input, IOutput $output)
 {
     if ($input->getOption('--silent')) {
         $input->setInputVerbosity(InputVerbosity::SILENT);
         $output->setOutputVerbosity(OutputVerbosity::SILENT);
     }
 }
 /**
  * @param ICommand $command
  */
 public function render(ICommand $command)
 {
     $description = $command->getDescription();
     if ($description) {
         $this->output->writeLine("<keyword>{$description}</keyword>");
     }
 }
 function it_defaults_to_normal_format(IInput $input, IOutput $output)
 {
     $input->hasOption('--format')->willReturn(true);
     $input->getOption('--format')->willReturn(null);
     $output->setOutputFormat(OutputFormat::NORMAL)->shouldBeCalled();
     $this->run($input, $output);
 }
 /**
  * @param IInput $input
  * @param IOutput $output
  */
 public function run(IInput $input, IOutput $output)
 {
     if ($input->hasOption('--verbosity')) {
         $verbosity = OutputVerbosity::getVerbosityForLevel($input->getOption('--verbosity', 0));
         $output->setOutputVerbosity($verbosity);
     }
 }
 function it_detects_verbosity(IInput $input, IOutput $output)
 {
     $input->hasOption('--verbosity')->willReturn(true);
     $input->getOption('--verbosity', 0)->willReturn(2);
     $output->setOutputVerbosity(OutputVerbosity::DEBUG)->shouldBeCalled();
     $this->run($input, $output);
 }
 function it_detects_silent_mode(IInput $input, IOutput $output)
 {
     $input->getOption('--silent')->willReturn(true);
     $input->setInputVerbosity(InputVerbosity::SILENT)->shouldBeCalled();
     $output->setOutputVerbosity(OutputVerbosity::SILENT)->shouldBeCalled();
     $this->run($input, $output);
 }
 /**
  * @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();
 }
 /**
  * @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;
     }
 }
Exemple #9
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");
     }
 }
 /**
  * @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);
 }
Exemple #12
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}");
 }
Exemple #13
0
 /**
  * @param IInput $input
  * @param IOutput $output
  */
 public function run(IInput $input, IOutput $output)
 {
     if ($input->hasOption('--format')) {
         $format = $input->getOption('--format');
         if ($format === 'plain') {
             $output->setOutputFormat(OutputFormat::PLAIN);
         } else {
             if ($format === 'raw') {
                 $output->setOutputFormat(OutputFormat::RAW);
             } else {
                 $output->setOutputFormat(OutputFormat::NORMAL);
             }
         }
     }
 }
Exemple #14
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');
     }
 }
Exemple #17
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();
 }
Exemple #18
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);
 }
Exemple #19
0
 /**
  * @param array $rows
  *
  * @return array
  */
 private function calculateColumnWidths(array $rows)
 {
     $widths = [];
     foreach ($rows as $row) {
         if ($row['type'] !== '@row') {
             continue;
         }
         foreach ($row['cols'] as $colIndex => $col) {
             $currentWidth = array_get($widths, $colIndex, 0);
             $col = $this->output->format($col, OutputFormat::PLAIN);
             $width = strlen($col);
             if ($width > $currentWidth) {
                 $widths[$colIndex] = $width;
             }
         }
     }
     return $widths;
 }
 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);
 }