Exemple #1
0
 public function testHasParameterOption()
 {
     $input = new ArrayInput(array('name' => 'Fabien', '--foo' => 'bar'));
     $this->assertTrue($input->hasParameterOption('--foo'), '->hasParameterOption() returns true if an option is present in the passed parameters');
     $this->assertFalse($input->hasParameterOption('--bar'), '->hasParameterOption() returns false if an option is not present in the passed parameters');
     $input = new ArrayInput(array('--foo'));
     $this->assertTrue($input->hasParameterOption('--foo'), '->hasParameterOption() returns true if an option is present in the passed parameters');
     $input = new ArrayInput(array('--foo', '--', '--bar'));
     $this->assertTrue($input->hasParameterOption('--bar'), '->hasParameterOption() returns true if an option is present in the passed parameters');
     $this->assertFalse($input->hasParameterOption('--bar', true), '->hasParameterOption() returns false if an option is present in the passed parameters after an end of options signal');
 }
 /**
  * Runs the current application.
  *
  * @param InputInterface  $input  An Input instance
  * @param OutputInterface $output An Output instance
  *
  * @return integer 0 if everything went fine, or an error code
  */
 public function doRun(InputInterface $input, OutputInterface $output)
 {
     $output->writeLn($this->getHeader());
     $name = $this->getCommandName($input);
     if (true === $input->hasParameterOption(array('--shell', '-s'))) {
         $shell = new Shell($this);
         $shell->run();
         return 0;
     }
     if (true === $input->hasParameterOption(array('--ansi'))) {
         $output->setDecorated(true);
     } elseif (true === $input->hasParameterOption(array('--no-ansi'))) {
         $output->setDecorated(false);
     }
     if (true === $input->hasParameterOption(array('--help', '-h'))) {
         if (!$name) {
             $name = 'help';
             $input = new ArrayInput(array('command' => 'help'));
         } else {
             $this->wantHelps = true;
         }
     }
     if (true === $input->hasParameterOption(array('--no-interaction', '-n'))) {
         $input->setInteractive(false);
     }
     if (function_exists('posix_isatty') && $this->getHelperSet()->has('dialog')) {
         $inputStream = $this->getHelperSet()->get('dialog')->getInputStream();
         if (!posix_isatty($inputStream)) {
             $input->setInteractive(false);
         }
     }
     if (true === $input->hasParameterOption(array('--quiet', '-q'))) {
         $output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
     } elseif (true === $input->hasParameterOption(array('--verbose', '-v'))) {
         $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE);
     }
     if (true === $input->hasParameterOption(array('--version', '-V'))) {
         $output->writeln($this->getLongVersion());
         return 0;
     }
     if (!$name) {
         $name = 'list';
         $input = new ArrayInput(array('command' => 'list'));
     }
     // the command name MUST be the first element of the input
     $command = $this->find($name);
     $this->runningCommand = $command;
     $statusCode = $command->run($input, $output);
     $this->runningCommand = null;
     # write Footer
     $output->writeLn($this->getFooter());
     return is_numeric($statusCode) ? $statusCode : 0;
 }
Exemple #3
0
 /**
  * Runs the current application.
  *
  * @param InputInterface  $input  An Input instance
  * @param OutputInterface $output An Output instance
  *
  * @return integer 0 if everything went fine, or an error code
  */
 public function doRun(InputInterface $input, OutputInterface $output)
 {
     $name = $this->getCommandName($input);
     if (true === $input->hasParameterOption(array('--ansi'))) {
         $output->setDecorated(true);
     } elseif (true === $input->hasParameterOption(array('--no-ansi'))) {
         $output->setDecorated(false);
     }
     if (true === $input->hasParameterOption(array('--help', '-h'))) {
         if (!$name) {
             $name = 'help';
             $input = new ArrayInput(array('command' => 'help'));
         } else {
             $this->wantHelps = true;
         }
     }
     if (true === $input->hasParameterOption(array('--no-interaction', '-n'))) {
         $input->setInteractive(false);
     }
     if (true === $input->hasParameterOption(array('--quiet', '-q'))) {
         $output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
     } elseif (true === $input->hasParameterOption(array('--verbose', '-v'))) {
         $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE);
     }
     if (true === $input->hasParameterOption(array('--version', '-V'))) {
         $output->writeln($this->getLongVersion());
         return 0;
     }
     if (!$name) {
         $name = 'list';
         $input = new ArrayInput(array('command' => 'list'));
     }
     // the command name MUST be the first element of the input
     $command = $this->find($name);
     $this->runningCommand = $command;
     $statusCode = $command->run($input, $output);
     $this->runningCommand = null;
     return is_numeric($statusCode) ? $statusCode : 0;
 }