getDefaultSubCommands() public method

Returns the commands that should be executed if no explicit command is passed.
public getDefaultSubCommands ( ) : CommandCollection
return CommandCollection The default commands.
Esempio n. 1
0
 /**
  * Renders the "Usage" section.
  *
  * @param BlockLayout $layout  The layout.
  * @param Command     $command The command to render.
  */
 protected function renderUsage(BlockLayout $layout, Command $command)
 {
     $formatsToPrint = array();
     // Start with the default commands
     if ($command->hasDefaultSubCommands()) {
         // If the command has default commands, print them
         foreach ($command->getDefaultSubCommands() as $subCommand) {
             // The name of the sub command is only optional (i.e. printed
             // wrapped in brackets: "[sub]") if the command is not
             // anonymous
             $nameOptional = !$subCommand->getConfig()->isAnonymous();
             $formatsToPrint[] = array($subCommand->getArgsFormat(), $nameOptional);
         }
     } else {
         // Otherwise print the command's usage itself
         $formatsToPrint[] = array($command->getArgsFormat(), false);
     }
     // Add remaining sub-commands
     foreach ($command->getSubCommands() as $subCommand) {
         // Don't duplicate default commands
         if (!$subCommand->getConfig()->isDefault()) {
             $formatsToPrint[$subCommand->getName()] = array($subCommand->getArgsFormat(), false);
         }
     }
     $appName = $command->getApplication()->getConfig()->getName();
     $prefix = count($formatsToPrint) > 1 ? '    ' : '';
     $layout->add(new Paragraph('<b>USAGE</b>'));
     $layout->beginBlock();
     foreach ($formatsToPrint as $vars) {
         $this->renderSynopsis($layout, $vars[0], $appName, $prefix, $vars[1]);
         $prefix = 'or: ';
     }
     if ($command->hasAliases()) {
         $layout->add(new EmptyLine());
         $this->renderAliases($layout, $command->getAliases());
     }
     $layout->endBlock();
     $layout->add(new EmptyLine());
 }
Esempio n. 2
0
 public function testGetDefaultSubCommands()
 {
     $config = new CommandConfig('command');
     $config->addSubCommandConfig($subConfig1 = new SubCommandConfig('sub1'));
     $config->addSubCommandConfig($subConfig2 = new SubCommandConfig('sub2'));
     $config->addSubCommandConfig($subConfig3 = new SubCommandConfig('sub3'));
     $subConfig1->markDefault();
     $subConfig3->markDefault();
     $command = new Command($config);
     $this->assertEquals(new CommandCollection(array(new Command($subConfig1, null, $command), new Command($subConfig3, null, $command))), $command->getDefaultSubCommands());
 }
Esempio n. 3
0
 /**
  * @param RawArgs $args
  * @param Command $currentCommand
  *
  * @return ResolveResult
  */
 private function processDefaultSubCommands(RawArgs $args, Command $currentCommand)
 {
     if ($result = $this->processDefaultCommands($args, $currentCommand->getDefaultSubCommands())) {
         return $result;
     }
     // No default commands, return the current command
     return new ResolveResult($currentCommand, $args);
 }