Returns all sub-commands that are not anonymous.
public getNamedSubCommands ( ) : |
||
return | The named commands. |
/** * {@inheritdoc} */ protected function renderHelp(BlockLayout $layout) { $help = $this->command->getConfig()->getHelp(); $argsFormat = $this->command->getArgsFormat(); $subCommands = $this->command->getNamedSubCommands(); $this->renderUsage($layout, $this->command); if ($argsFormat->hasArguments()) { $this->renderArguments($layout, $argsFormat->getArguments()); } if (!$subCommands->isEmpty()) { $this->renderSubCommands($layout, $subCommands); } if ($argsFormat->hasOptions(false)) { $this->renderOptions($layout, $argsFormat->getOptions(false)); } if ($argsFormat->getBaseFormat() && $argsFormat->getBaseFormat()->hasOptions()) { $this->renderGlobalOptions($layout, $argsFormat->getBaseFormat()->getOptions()); } if ($help) { $this->renderDescription($layout, $help); } }
public function testGetNamedSubCommands() { $config = new CommandConfig('command'); $config->addSubCommandConfig($subConfig1 = new SubCommandConfig('sub1')); $config->addSubCommandConfig($subConfig2 = new SubCommandConfig('sub2')); $config->addSubCommandConfig($subConfig3 = new SubCommandConfig('sub3')); $subConfig2->markAnonymous(); $subConfig3->markDefault(); $command = new Command($config); $this->assertEquals(new CommandCollection(array(new Command($subConfig1, null, $command), new Command($subConfig3, null, $command))), $command->getNamedSubCommands()); }
/** * @param RawArgs $args * @param Command $currentCommand * @param string[] $optionsToTest * * @return ResolveResult */ private function processOptions(RawArgs $args, Command $currentCommand, array $optionsToTest) { foreach ($optionsToTest as $option) { $commands = $currentCommand->getNamedSubCommands(); if (!$commands->contains($option)) { continue; } $nextCommand = $commands->get($option); if (!$nextCommand->getConfig() instanceof OptionCommandConfig) { break; } $currentCommand = $nextCommand; } return $this->processDefaultSubCommands($args, $currentCommand); }