Esempio n. 1
0
 /**
  * Return an array of parameters that should be passed to the callable.
  * They should have the correct name indexes, the order does not matter
  * as Auryn will inject them correctly.
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return array
  */
 function parseInput(InputInterface $input, OutputInterface $output)
 {
     $params = [];
     foreach ($this->getDefinition()->getArguments() as $argument) {
         $name = $argument->getName();
         $params[$name] = $input->getArgument($name);
     }
     foreach ($this->getDefinition()->getOptions() as $option) {
         $name = $option->getName();
         $params[$name] = $input->getOption($name);
     }
     return $params;
 }
Esempio n. 2
0
 /**
  * Asks a question to the user.
  *
  * @param InputInterface  $input    An InputInterface instance
  * @param OutputInterface $output   An OutputInterface instance
  * @param Question        $question The question to ask
  *
  * @return string The user answer
  *
  * @throws \RuntimeException If there is no data to read in the input stream
  */
 public function ask(InputInterface $input, OutputInterface $output, Question $question)
 {
     if (!$input->isInteractive()) {
         return $question->getDefault();
     }
     if (!$question->getValidator()) {
         return $this->doAsk($output, $question);
     }
     $that = $this;
     $interviewer = function () use($output, $question, $that) {
         return $that->doAsk($output, $question);
     };
     return $this->validateAttempts($interviewer, $output, $question);
 }
Esempio n. 3
0
 function getCallable()
 {
     $callable = function () {
         if ($this->input->getOption('xml')) {
             $this->input->setOption('format', 'xml');
         }
         $helper = new DescriptorHelper();
         $helper->describe($this->output, $this->getApplication(), array('format' => $this->input->getOption('format'), 'raw_text' => $this->input->getOption('raw'), 'namespace' => $this->input->getArgument('namespace')));
     };
     return $callable;
 }
Esempio n. 4
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (null === $this->command) {
         $this->command = $this->getApplication()->find($input->getArgument('command_name'));
     }
     if ($input->getOption('xml')) {
         $input->setOption('format', 'xml');
     }
     $helper = new DescriptorHelper();
     $helper->describe($output, $this->command, array('format' => $input->getOption('format'), 'raw' => $input->getOption('raw')));
     $this->command = null;
 }
Esempio n. 5
0
 /**
  * Gets the name of the command based on input.
  *
  * @param InputInterface $input The input interface
  *
  * @return string The command name
  */
 protected function getCommandName(InputInterface $input)
 {
     return $input->getFirstArgument();
 }
Esempio n. 6
0
 /**
  * Runs the command.
  *
  * The code to execute is either defined directly with the
  * setCode() method or by overriding the execute() method
  * in a sub-class.
  *
  * @param InputInterface  $input  An InputInterface instance
  * @param OutputInterface $output An OutputInterface instance
  *
  * @return array An array of [null, $callable, $parameters] that should be called for the command
  *
  * @throws \Exception
  *
  * @see setCode()
  * @see execute()
  *
  * @api
  */
 public function run(InputInterface $input, OutputInterface $output)
 {
     if (null !== $this->processTitle) {
         if (function_exists('cli_set_process_title')) {
             cli_set_process_title($this->processTitle);
         } elseif (function_exists('setproctitle')) {
             setproctitle($this->processTitle);
         } elseif (OutputInterface::VERBOSITY_VERY_VERBOSE === $output->getVerbosity()) {
             $output->writeln('<comment>Install the proctitle PECL to be able to change the process title.</comment>');
         }
     }
     // force the creation of the synopsis before the merge with the app definition
     $this->getSynopsis();
     // add the application arguments and options
     $this->mergeApplicationDefinition();
     // bind the input against the command specific arguments/options
     try {
         $input->bind($this->definition);
     } catch (\Exception $e) {
         if (!$this->ignoreValidationErrors) {
             throw $e;
         }
     }
     $this->initialize($input, $output);
     if ($input->isInteractive()) {
         $this->interact($input, $output);
     }
     $input->validate();
     $callable = $this->getCallable();
     $params = $this->parseInput($input, $output);
     return new ParsedCommand($callable, $params, $input, $output);
 }