Example #1
0
 /**
  * @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);
     }
 }
 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);
 }
Example #3
0
 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);
 }
Example #4
0
 /**
  * @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);
     }
 }
Example #5
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);
 }
 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);
 }
Example #7
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();
 }
Example #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;
     }
 }
Example #9
0
 function it_uses_self_as_command(IInput $input)
 {
     $console = new Console();
     $input->hasArgument('command')->willReturn(false);
     $input->getCommand()->willReturn(new Command());
     $output = new Output();
     $output->setEnableBuffering(true);
     $this->run($input, $output, $console);
 }
Example #10
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;
     }
 }
Example #11
0
 function it_chooses(IInput $input)
 {
     $input->readLine()->willReturn(1);
     $this->choose('question', ['key1' => 'option1', 'key2' => 'option2'], false)->shouldBe('key1');
     $input->readLine()->willReturn(2);
     $this->choose('question', ['key1' => 'option1', 'key2' => 'option2'], false)->shouldBe('key2');
     $input->readLine()->willReturn(3, 4, 1);
     $this->choose('question', ['key1' => 'option1', 'key2' => 'option2'], false)->shouldBe('key1');
     $input->readLine()->willReturn(3, 4, 'key2');
     $this->choose('question', ['key1' => 'option1', 'key2' => 'option2'])->shouldBe('key2');
 }
Example #12
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);
             }
         }
     }
 }
Example #13
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 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');
     }
 }
Example #15
0
 /**
  * @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_detects_no_interaction_mode(IInput $input, IOutput $output)
 {
     $input->getOption('--no-interaction')->willReturn(true);
     $input->setInputVerbosity(InputVerbosity::SILENT)->shouldBeCalled();
     $this->run($input, $output);
 }
 /**
  * @param IInput $input
  * @param IOutput $output
  */
 public function run(IInput $input, IOutput $output)
 {
     if ($input->getOption('--no-interaction')) {
         $input->setInputVerbosity(InputVerbosity::SILENT);
     }
 }
Example #18
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);
 }
 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);
 }