hasDefaultSubCommands() public method

Returns whether the command has any default commands.
See also: getDefaultSubCommands()
public hasDefaultSubCommands ( ) : boolean
return boolean Returns `true` if the command has default commands and `false` otherwise.
Ejemplo 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());
 }
Ejemplo n.º 2
0
 public function testHasNoDefaultSubCommands()
 {
     $config = new CommandConfig('command');
     $config->addSubCommandConfig(new SubCommandConfig('sub'));
     $command = new Command($config);
     $this->assertFalse($command->hasDefaultSubCommands());
 }