getNamedCommands() public method

Returns the commands that are not anonymous.
public getNamedCommands ( ) : CommandCollection
return Webmozart\Console\Api\Command\CommandCollection The named commands.
Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 protected function renderHelp(BlockLayout $layout)
 {
     $help = $this->application->getConfig()->getHelp();
     $commands = $this->application->getNamedCommands();
     $globalArgsFormat = $this->application->getGlobalArgsFormat();
     $argsFormat = ArgsFormat::build()->addArgument(new Argument('command', Argument::REQUIRED, 'The command to execute'))->addArgument(new Argument('arg', Argument::MULTI_VALUED, 'The arguments of the command'))->addOptions($globalArgsFormat->getOptions())->getFormat();
     $this->renderName($layout, $this->application);
     $this->renderUsage($layout, $this->application, $argsFormat);
     $this->renderArguments($layout, $argsFormat->getArguments());
     if ($argsFormat->hasOptions()) {
         $this->renderGlobalOptions($layout, $argsFormat->getOptions());
     }
     if (!$commands->isEmpty()) {
         $this->renderCommands($layout, $commands);
     }
     if ($help) {
         $this->renderDescription($layout, $help);
     }
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 public function resolveCommand(RawArgs $args, Application $application)
 {
     $tokens = $args->getTokens();
     $namedCommands = $application->getNamedCommands();
     $argumentsToTest = $this->getArgumentsToTest($tokens);
     $optionsToTest = $this->getOptionsToTest($tokens);
     // Try to find a command for the passed arguments and options.
     if ($result = $this->processArguments($args, $namedCommands, $argumentsToTest, $optionsToTest)) {
         return $this->createResolvedCommand($result);
     }
     // If arguments were passed, we did not find the matching command.
     if ($argumentsToTest) {
         throw CannotResolveCommandException::nameNotFound(reset($argumentsToTest), $namedCommands);
     }
     // If no arguments were passed, run the application's default command.
     if ($result = $this->processDefaultCommands($args, $application->getDefaultCommands())) {
         return $this->createResolvedCommand($result);
     }
     // No default command is configured.
     throw CannotResolveCommandException::noDefaultCommand();
 }