/**
  * @param Command $command
  * @param InputInterface $input
  */
 protected function addOptionsToCommand(Command $command, InputInterface $input)
 {
     $inputDefinition = $command->getApplication()->getDefinition();
     $inputDefinition->addOption(new InputOption(self::DISABLE_OPTIONAL_LISTENERS, null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, sprintf('Disable optional listeners, "%s" to disable all listeners, ' . 'command "%s" shows all listeners', self::ALL_OPTIONAL_LISTENERS_VALUE, OptionalListenersCommand::NAME)));
     $command->mergeApplicationDefinition();
     $input->bind($command->getDefinition());
 }
Example #2
0
 /**
  * Implements symfony/console doRun launching method
  * @param InputInterface  $input  Underlying symfony/console InputInterface
  * @param OutputInterface $output Underlying symfony/console OutputInterface
  */
 public function doRun(InputInterface $input, OutputInterface $output)
 {
     $this->input = $input;
     $this->output = $output;
     // Binding input definition
     $this->input->bind(new \SCQAT\CLI\Definition());
     // Determining analyzed directory
     $analyzedDirectory = "";
     $optionDirectory = $this->input->getOption("directory");
     if (!empty($optionDirectory)) {
         $analyzedDirectory = rtrim($this->input->getOption("directory"), "/") . "/";
     }
     $this->analyzedDirectory = realpath($analyzedDirectory) . DIRECTORY_SEPARATOR;
     // Creating SCQAT Context
     $context = new \SCQAT\Context($this->vendorDirectory, $this->analyzedDirectory);
     // Attach CLI specific report hooks to the context if configuration allows it
     if (in_array("console", $context->configuration["Reports"])) {
         $context->attachReportHooks(new \SCQAT\CLI\ReportHooks($this->output, $this->input->getOption("verbose")));
     }
     // Gathering files to analyze
     $files = $this->gatherFiles($context);
     if (count($files)) {
         // Attach gathered files to the context
         $context->files = $files;
         // Run SCQAT runner on the context
         $this->runner->run($context);
     }
     // Exit CLI application on error if any were found
     if ($context->hadError !== false) {
         return 1;
     }
 }
 function it_updates_a_avaivalble_exchange_rate(ContainerInterface $container, InputInterface $input, OutputInterface $output, ImporterInterface $importer, CurrencyInterface $currency)
 {
     $input->bind(Argument::any())->shouldBeCalled();
     $input->isInteractive()->shouldBeCalled();
     $input->validate()->shouldBeCalled();
     $output->writeln('Fetching data from external database.')->shouldBeCalled();
     $input->getArgument('importer')->shouldBeCalled()->willreturn('importer');
     $container->get('sylius.currency_importer.importer')->shouldBeCalled()->willreturn($importer);
     $importer->import()->shouldBeCalled();
     $output->writeln('Saving updated exchange rates.')->shouldBeCalled();
     $this->setContainer($container);
     $this->run($input, $output);
 }
 function it_executes(InputInterface $input, OutputInterface $output, UserCommandBus $commandBus)
 {
     $input->getArgument('email')->shouldBeCalled()->willReturn('*****@*****.**');
     $input->getArgument('password')->shouldBeCalled()->willReturn(123456);
     $input->hasArgument('command')->shouldBeCalled()->willReturn(true);
     $input->getArgument('command')->shouldBeCalled()->willReturn('command');
     $input->bind(Argument::any())->shouldBeCalled();
     $input->isInteractive()->shouldBeCalled()->willReturn(true);
     $input->validate()->shouldBeCalled();
     $commandBus->handle(Argument::type(WithoutOldPasswordChangeUserPasswordCommand::class))->shouldBeCalled()->willReturn(['email' => '*****@*****.**', 'password' => 123456]);
     $output->writeln(sprintf('Changed password of <comment>%s</comment> %s', '*****@*****.**', 'user'))->shouldBeCalled();
     $this->run($input, $output);
 }
Example #5
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @throws \Exception
  */
 public function loadCommands(InputInterface $input, OutputInterface $output)
 {
     // $application is required to be defined in the register_command scripts
     $application = $this->application;
     $inputDefinition = $application->getDefinition();
     $inputDefinition->addOption(new InputOption('no-warnings', null, InputOption::VALUE_NONE, 'Skip global warnings, show command output only', null));
     try {
         $input->bind($inputDefinition);
     } catch (\RuntimeException $e) {
         //expected if there are extra options
     }
     if ($input->getOption('no-warnings')) {
         $output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
     }
     require_once __DIR__ . '/../../../core/register_command.php';
     if ($this->config->getSystemValue('installed', false)) {
         if (\OCP\Util::needUpgrade()) {
             $output->writeln("ownCloud or one of the apps require upgrade - only a limited number of commands are available");
             $output->writeln("You may use your browser or the occ upgrade command to do the upgrade");
         } elseif ($this->config->getSystemValue('maintenance', false)) {
             $output->writeln("ownCloud is in maintenance mode - no app have been loaded");
         } else {
             OC_App::loadApps();
             foreach (\OC::$server->getAppManager()->getInstalledApps() as $app) {
                 $appPath = \OC_App::getAppPath($app);
                 if ($appPath === false) {
                     continue;
                 }
                 \OC::$loader->addValidRoot($appPath);
                 $file = $appPath . '/appinfo/register_command.php';
                 if (file_exists($file)) {
                     require $file;
                 }
             }
         }
     } else {
         $output->writeln("ownCloud is not installed - only a limited number of commands are available");
     }
     $input = new ArgvInput();
     if ($input->getFirstArgument() !== 'check') {
         $errors = \OC_Util::checkServer(\OC::$server->getConfig());
         if (!empty($errors)) {
             foreach ($errors as $error) {
                 $output->writeln((string) $error['error']);
                 $output->writeln((string) $error['hint']);
                 $output->writeln('');
             }
             throw new \Exception("Environment not properly prepared.");
         }
     }
 }
 function it_executes(InputInterface $input, OutputInterface $output, UserCommandBus $commandBus)
 {
     $input->getArgument('email')->shouldBeCalled()->willReturn('*****@*****.**');
     $input->getArgument('password')->shouldBeCalled()->willReturn(123456);
     $input->getArgument('roles')->shouldBeCalled()->willReturn(['ROLE_USER', 'ROLE_ADMIN']);
     $input->hasArgument('command')->shouldBeCalled()->willReturn(true);
     $input->getArgument('command')->shouldBeCalled()->willReturn('command');
     $input->bind(Argument::any())->shouldBeCalled();
     $input->isInteractive()->shouldBeCalled()->willReturn(true);
     $input->validate()->shouldBeCalled();
     $commandBus->handle(Argument::type(SignUpUserCommand::class))->shouldBeCalled();
     $output->writeln(sprintf('Created %s: <comment>%s</comment>', 'user', '*****@*****.**'))->shouldBeCalled();
     $this->run($input, $output);
 }
 public function testShouldPropagateCustomOptionsIntoProcess()
 {
     $this->input = new StringInput('trolling chrome' . ' --' . RunTestsCommand::OPTION_SERVER_URL . '=http://foo.bar:1337' . ' --' . RunTestsCommand::OPTION_FIXTURES_DIR . '=custom-fixtures-dir/' . ' --' . RunTestsCommand::OPTION_LOGS_DIR . '=custom-logs-dir/' . ' --' . RunTestsCommand::OPTION_PUBLISH_RESULTS);
     $this->input->bind($this->command->getDefinition());
     // Redeclare creator so it uses the new input
     $this->creator = new ProcessSetCreator($this->command, $this->input, $this->bufferedOutput, $this->publisherMock);
     $files = $this->findDummyTests('DummyTest.php');
     // find only one file (we don't need more for the test)
     $processSet = $this->creator->createFromFiles($files, [], []);
     /** @var Process $process */
     $process = $processSet->get(ProcessSet::PROCESS_STATUS_QUEUED)[self::NAME_DUMMY_TEST]->process;
     $processEnv = $process->getEnv();
     $this->assertArraySubset(['BROWSER_NAME' => 'chrome', 'ENV' => 'trolling', 'SERVER_URL' => 'http://foo.bar:1337', 'PUBLISH_RESULTS' => '1', 'FIXTURES_DIR' => 'custom-fixtures-dir/', 'LOGS_DIR' => 'custom-logs-dir/'], $processEnv);
 }
Example #8
0
 public function doRun(InputInterface $input, OutputInterface $output)
 {
     $input->bind($this->getDefinition());
     $options = $input->getOptions();
     $this->setConfigurationOverride($options['config']);
     $this->setCatchExceptions(true);
     $imageFinder = new Image\Finder($this);
     $image = Image\Image::createFromConfig($this->getConfiguration());
     $this->get('install:assets')->inject($imageFinder);
     $this->get('refresh:thumbnails')->inject($image, $imageFinder);
     $this->get('refresh:covers')->inject($image, $imageFinder);
     $this->get('refresh:json')->inject($imageFinder);
     return parent::doRun($input, $output);
 }
 function it_can_output_a_message(HelloService $helloService, InputInterface $input, OutputInterface $output)
 {
     //ARRANGE
     // Some shit the Symfony Console component needs to be testable
     $input->bind(Argument::any())->shouldBeCalled();
     $input->isInteractive(Argument::any())->shouldBeCalled();
     $input->validate(Argument::any())->shouldBeCalled();
     // Prep the service
     $helloService->getGreeting(Argument::type('\\CodeKata\\RomanNumerals\\Domain\\Name'))->willReturn('Hello, Sam');
     // Give the command an input
     $input->getArgument('name')->willReturn('Sam');
     // ASSERT
     $output->writeln('Hello, Sam')->shouldBeCalled();
     // ACT
     $this->run($input, $output);
 }
 function it_updates_all_exchange_rate(ContainerInterface $container, InputInterface $input, OutputInterface $output, EntityRepository $repository, ImporterInterface $importer, CurrencyInterface $currency)
 {
     $input->bind(Argument::any())->shouldBeCalled();
     $input->isInteractive()->shouldBeCalled();
     $input->validate()->shouldBeCalled();
     $output->writeln('Fetching data from external database.')->shouldBeCalled();
     $input->hasOption('all')->shouldBeCalled()->willreturn(true);
     $container->get('sylius.repository.currency')->shouldBeCalled()->willreturn($repository);
     $repository->findAll()->shouldBeCalled()->willreturn(array($currency));
     $input->getArgument('importer')->shouldBeCalled()->willreturn('importer');
     $container->get('sylius.currency_importer.importer')->shouldBeCalled()->willreturn($importer);
     $importer->import(array($currency))->shouldBeCalled();
     $output->writeln('Saving updated exchange rates.')->shouldBeCalled();
     $this->setContainer($container);
     $this->run($input, $output);
 }
 public function it_create_client(ContainerInterface $container, InputInterface $input, OutputInterface $output, ClientManager $clientManager, Client $client)
 {
     $container->get('fos_oauth_server.client_manager.default')->willReturn($clientManager);
     $clientManager->createClient()->willReturn($client);
     $input->getOption('redirect-uri')->willReturn(array('redirect-uri'));
     $input->getOption('grant-type')->willReturn(array('grant-type'));
     $client->setRedirectUris(array('redirect-uri'))->shouldBeCalled();
     $client->setAllowedGrantTypes(array('grant-type'))->shouldBeCalled();
     $clientManager->updateClient($client)->shouldBeCalled();
     $client->getPublicId()->shouldBeCalled();
     $client->getSecret()->shouldBeCalled();
     $output->writeln(Argument::type('string'))->shouldBeCalled();
     $this->setContainer($container);
     $input->bind(Argument::any())->shouldBeCalled();
     $input->isInteractive()->shouldBeCalled();
     $input->validate()->shouldBeCalled();
     $this->run($input, $output);
 }
 function it_executes(ContainerInterface $container, ClientManager $clientManager, ClientInterface $client, InputInterface $input, OutputInterface $output)
 {
     $container->get('fos_oauth_server.client_manager.default')->shouldBeCalled()->willReturn($clientManager);
     $clientManager->createClient()->shouldBeCalled()->willReturn($client);
     $input->hasArgument('command')->shouldBeCalled()->willReturn(true);
     $input->getArgument('command')->shouldBeCalled()->willReturn('command');
     $input->bind(Argument::any())->shouldBeCalled();
     $input->isInteractive()->shouldBeCalled()->willReturn(false);
     $input->validate()->shouldBeCalled();
     $input->getOption('redirect-uri')->shouldBeCalled()->willReturn(['the-redirect-uri']);
     $client->setRedirectUris(['the-redirect-uri'])->shouldBeCalled();
     $input->getOption('grant-type')->shouldBeCalled()->willReturn(['the-grant-type']);
     $client->setAllowedGrantTypes(['the-grant-type'])->shouldBeCalled();
     $clientManager->updateClient($client)->shouldBeCalled();
     $client->getPublicId()->shouldBeCalled()->willReturn('public-id');
     $client->getSecret()->shouldBeCalled()->willReturn('secret');
     $output->writeln(sprintf('A new client with public id <info>%s</info>, secret <info>%s</info> has been added', 'public-id', 'secret'))->shouldBeCalled();
     $this->run($input, $output);
 }
Example #13
0
 function it_executes(ContainerInterface $container, UserFactory $userFactory, UserInterface $user, UserManager $userManager, InputInterface $input, OutputInterface $output)
 {
     $container->get('kreta_user.factory.user')->shouldBeCalled()->willReturn($userFactory);
     $input->bind(Argument::any())->shouldBeCalled();
     $input->isInteractive()->shouldBeCalled()->willReturn(true);
     $input->validate()->shouldBeCalled();
     $input->hasArgument('command')->shouldBeCalled()->willReturn(true);
     $input->getArgument('command')->shouldBeCalled()->willReturn('command');
     $input->getArgument('email')->shouldBeCalled()->willReturn('*****@*****.**');
     $input->getArgument('username')->shouldBeCalled()->willReturn('kreta');
     $input->getArgument('firstName')->shouldBeCalled()->willReturn('Kreta');
     $input->getArgument('lastName')->shouldBeCalled()->willReturn('User');
     $input->getArgument('password')->shouldBeCalled()->willReturn('123456');
     $userFactory->create('*****@*****.**', 'kreta', 'Kreta', 'User', true)->shouldBeCalled()->willReturn($user);
     $user->setPlainPassword('123456')->shouldBeCalled()->willReturn($user);
     $container->get('fos_user.user_manager')->shouldBeCalled()->willReturn($userManager);
     $userManager->updatePassword($user)->shouldBeCalled();
     $userManager->updateUser($user)->shouldBeCalled()->willReturn($user);
     $user->getUsername()->shouldBeCalled()->willReturn('kreta');
     $output->writeln(sprintf('A new <info>%s</info> user has been created', 'kreta'))->shouldBeCalled();
     $this->run($input, $output);
 }
Example #14
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 int The command exit code
  *
  * @throws \Exception
  *
  * @see setCode()
  * @see execute()
  */
 public function run(InputInterface $input, OutputInterface $output)
 {
     // force the creation of the synopsis before the merge with the app definition
     $this->getSynopsis(true);
     $this->getSynopsis(false);
     // add the application arguments and options
     $this->mergeApplicationDefinition();
     // bind the input against the command specific arguments/options
     try {
         $input->bind($this->definition);
     } catch (ExceptionInterface $e) {
         if (!$this->ignoreValidationErrors) {
             throw $e;
         }
     }
     $this->initialize($input, $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>');
         }
     }
     if ($input->isInteractive()) {
         $this->interact($input, $output);
     }
     // The command name argument is often omitted when a command is executed directly with its run() method.
     // It would fail the validation if we didn't make sure the command argument is present,
     // since it's required by the application.
     if ($input->hasArgument('command') && null === $input->getArgument('command')) {
         $input->setArgument('command', $this->getName());
     }
     $input->validate();
     if ($this->code) {
         $statusCode = call_user_func($this->code, $input, $output);
     } else {
         $statusCode = $this->execute($input, $output);
     }
     return is_numeric($statusCode) ? (int) $statusCode : 0;
 }
 /**
  * Runs the command.
  *
  * Before the decorated command is run, a lock is requested.
  * When failed to acquire the lock, the command exits.
  *
  * @param InputInterface  $input  An InputInterface instance
  * @param OutputInterface $output An OutputInterface instance
  *
  * @return int The command exit code
  */
 public function run(InputInterface $input, OutputInterface $output)
 {
     $this->mergeApplicationDefinition();
     $input->bind($this->getDefinition());
     $lock = $this->getLockHandler($input);
     if (!$lock->lock()) {
         $this->writeLockedMessage($input, $output);
         return 1;
     }
     try {
         return $this->decoratedCommand->run($input, $output);
     } finally {
         $lock->release();
     }
 }
Example #16
0
 public function run(InputInterface $input, OutputInterface $output)
 {
     $this->getSynopsis();
     $this->mergeApplicationDefinition();
     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();
     if ($this->code) {
         $statusCode = call_user_func($this->code, $input, $output);
     } else {
         $statusCode = $this->execute($input, $output);
     }
     return is_numeric($statusCode) ? (int) $statusCode : 0;
 }
 function let(InputInterface $input)
 {
     $input->bind(Argument::cetera())->willReturn();
     $input->isInteractive()->willReturn(false);
     $input->validate()->willReturn();
 }
Example #18
0
 /**
  * Prepare ExtendedConsoleEvent that could be passed to onCommandRunTestsInit().
  *
  * @param Command $command
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return ExtendedConsoleEvent
  */
 protected function prepareExtendedConsoleEvent($command, $input, $output)
 {
     // Trigger event to add the xdebug option to the command and bind the definition to the input
     $this->listener->onCommandConfigure(new BasicConsoleEvent($command));
     $input->bind($command->getDefinition());
     $event = new ExtendedConsoleEvent($command, $input, $output);
     return $event;
 }
Example #19
0
public function run(InputInterface $input, OutputInterface $output)
{

 $this->getSynopsis(true);
$this->getSynopsis(false);


 $this->mergeApplicationDefinition();


 try {
$input->bind($this->definition);
} catch (ExceptionInterface $e) {
if (!$this->ignoreValidationErrors) {
throw $e;
}
}

$this->initialize($input, $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>');
}
}

if ($input->isInteractive()) {
$this->interact($input, $output);
}


 
 
 if ($input->hasArgument('command') && null === $input->getArgument('command')) {
$input->setArgument('command', $this->getName());
}

$input->validate();

if ($this->code) {
$statusCode = call_user_func($this->code, $input, $output);
} else {
$statusCode = $this->execute($input, $output);
}

return is_numeric($statusCode) ? (int) $statusCode : 0;
}
 /**
  * @param Command         $command
  * @param InputInterface  $input
  * @param InputDefinition $inputDefinition
  */
 private function setInputDefinition(Command $command, InputInterface $input, InputDefinition $inputDefinition)
 {
     $command->setDefinition($inputDefinition);
     $command->mergeApplicationDefinition();
     $input->bind($inputDefinition);
 }
 /**
  * @override
  */
 public function run(InputInterface $input, OutputInterface $output)
 {
     // Parse input
     try {
         $this->mergeApplicationDefinition();
         $input->bind($this->getDefinition());
     } catch (ExceptionInterface $e) {
         // ignore invalid options/arguments for now, we are just modifying the input.
     }
     // Validate required options
     foreach ($this->getInputConfigOptions() as $option) {
         if ($option->isRequired() && $input->getOption($option->getName()) === null) {
             throw new \InvalidArgumentException(sprintf('The "%s" option is not specified and not found in the config "%s"', $option->getName(), $option->getConfigPath()));
         }
     }
     // Process callbacks from options.
     if ($this->shouldProcessCallbacks()) {
         $this->processCallbacks($input);
     }
     return parent::run($input, $output);
 }
 /**
  * Helps to set the environment for the application. Basically does these two things:.
  *
  *  * applies the input definition to the input and sets the result as property of the application.
  *  * prepares the outputinterface
  *
  * @param InputInterface  $input
  * @param OutputInterface $output
  */
 protected function prepEnvironment(InputInterface $input, OutputInterface $output)
 {
     $input->bind(new InputDefinition(array(new InputOption('local_ref', 'lref', InputOption::VALUE_REQUIRED, 'local ref'), new InputOption('local_sha', 'lsha', InputOption::VALUE_REQUIRED, 'local sha'), new InputOption('remote_ref', 'rref', InputOption::VALUE_REQUIRED, 'remote ref'), new InputOption('remote_sha', 'rsha', InputOption::VALUE_REQUIRED, 'remote sha'))));
     $this->input = $input->getOptions();
     $output->getFormatter()->setStyle('error', new OutputFormatterStyle('white', 'red', array('bold')));
     $output->getFormatter()->setStyle('warning', new OutputFormatterStyle('black', 'yellow', array('bold')));
     $output->getFormatter()->setStyle('good', new OutputFormatterStyle('white', 'green', array('bold')));
     $this->output = $output;
 }
 /**
  * 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 int The command exit code
  *
  * @throws \Exception
  *
  * @see setCode()
  * @see execute()
  *
  * @api
  */
 public function run(InputInterface $input, OutputInterface $output)
 {
     // force the creation of the synopsis before the merge with the app definition
     $this->getSynopsis(true);
     $this->getSynopsis(false);
     // 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 (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>');
         }
     }
     if ($input->isInteractive()) {
         $this->interact($input, $output);
     }
     $input->validate();
     if ($this->code) {
         $statusCode = call_user_func($this->code, $input, $output);
     } else {
         $statusCode = $this->execute($input, $output);
     }
     return is_numeric($statusCode) ? (int) $statusCode : 0;
 }
Example #24
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 int The command exit code
  *
  * @throws \Exception
  *
  * @see setCode()
  * @see execute()
  */
 public function run(InputInterface $input, OutputInterface $output)
 {
     // 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);
     }
     // The command name argument is often omitted when a command is executed directly with its run() method.
     // It would fail the validation if we didn't make sure the command argument is present,
     // since it's required by the application.
     if ($input->hasArgument('command') && null === $input->getArgument('command')) {
         $input->setArgument('command', $this->getName());
     }
     $input->validate();
     if ($this->code) {
         $statusCode = call_user_func($this->code, $input, $output);
     } else {
         $statusCode = $this->execute($input, $output);
     }
     return is_numeric($statusCode) ? (int) $statusCode : 0;
 }
Example #25
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 integer The command exit code
  *
  * @see setCode()
  * @see execute()
  *
  * @api
  */
 public function run(InputInterface $input, OutputInterface $output)
 {
     // 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();
     if ($this->code) {
         return call_user_func($this->code, $input, $output);
     }
     return $this->execute($input, $output);
 }
Example #26
0
 /**
  * @{inheritDoc}
  */
 public function getHostNames(InputInterface $input)
 {
     $hosts = array();
     $input->bind($this->getDefaultInputDefinition());
     if ($input->hasArgument('host')) {
         $nicknames = explode(',', $input->getArgument('host'));
         foreach ($nicknames as $nick) {
             if ($nick == 'all' || $nick == '.') {
                 // Get all hosts
                 $hosts = array_keys($this->getHosts());
                 break;
             } elseif (array_key_exists($nick, $this->getHosts())) {
                 $hosts[] = $nick;
             } else {
                 throw new InvalidArgumentException('Invalid host:' . $nick);
             }
         }
     }
     return $hosts;
 }