예제 #1
0
 /**
  * Grab the input arguments for the given generator from the input, or ask interactively.
  * @param InputInterface        $input              Input from which the arguments should be resolved.
  * @param GeneratorInterface    $generator          The generator for which input arguments should be grabbed.
  * @param bool                  $forceInteractive   Try to run the interactive versions of asking for input.
  * @throws \RuntimeException
  * @return Arguments
  */
 public function resolve(InputInterface $input, GeneratorInterface $generator, $forceInteractive = false)
 {
     $definition = $generator->getDefinition();
     $definition = $this->mergeApplicationDefinition($definition);
     $definition = new InputDefinition($definition);
     $input = clone $input;
     try {
         $input->bind($definition);
         $input->validate();
     } catch (\Exception $ex) {
         $forceInteractive = true;
     }
     $arguments = array_merge($input->getArguments(), $input->getOptions());
     $arguments = new Arguments($arguments, $forceInteractive || $generator->requiresInteraction());
     return $arguments;
     if ($forceInteractive || $generator->requiresInteraction()) {
         if (!$input->isInteractive()) {
             throw new \RuntimeException("Cannot interact with user.");
         }
         $constraints = $generator->getConstraints();
         $questioner = new Questioner($inputTypeRegistry, $this->output, $this->helperSet, $constraints);
         $arguments = $generator->interact($arguments, $questioner);
     }
     return $arguments;
 }
예제 #2
0
 /**
  * Show the help for a single generator.
  * @param GeneratorInterface $generator
  * @param OutputInterface    $output
  */
 protected function showGeneratorHelp(GeneratorInterface $generator, OutputInterface $output)
 {
     $definition = new InputDefinition($generator->getDefinition());
     $output->writeln("<comment>Generator:</comment> <info>{$generator->getName()}</info>");
     $output->writeln(" {$generator->getDescription()}");
     $output->writeln("");
     $output->writeln("<comment>Usage:</comment>");
     $output->writeln(" {$this->getName()} {$generator->getName()} {$definition->getSynopsis()}");
     $output->writeln("");
     $descriptor = new DescriptorHelper();
     $descriptor->describe($output, $definition);
 }