buildArgsFormat() public method

Builds an {@link ArgsFormat} instance with the given base format.
public buildArgsFormat ( ArgsFormat $baseFormat = null ) : ArgsFormat
$baseFormat Webmozart\Console\Api\Args\Format\ArgsFormat The base format.
return Webmozart\Console\Api\Args\Format\ArgsFormat The built format for the console arguments.
Example #1
0
 public function testBuildAnonymousArgsFormat()
 {
     $baseFormat = new ArgsFormat();
     $this->config->setName('command');
     $this->config->setAliases(array('alias1', 'alias2'));
     $this->config->addOption('option');
     $this->config->addArgument('argument');
     $this->config->markAnonymous();
     $expected = ArgsFormat::build($baseFormat)->addArgument(new Argument('argument'))->addOption(new Option('option'))->getFormat();
     $this->assertEquals($expected, $this->config->buildArgsFormat($baseFormat));
 }
Example #2
0
 /**
  * Creates a new command.
  *
  * @param CommandConfig $config        The command configuration.
  * @param Application   $application   The console application.
  * @param Command       $parentCommand The parent command.
  *
  * @throws LogicException If the name of the command configuration is not set.
  */
 public function __construct(CommandConfig $config, Application $application = null, Command $parentCommand = null)
 {
     if (!$config->getName()) {
         throw new LogicException('The name of the command config must be set.');
     }
     $this->name = $config->getName();
     $this->shortName = $config instanceof OptionCommandConfig ? $config->getShortName() : null;
     $this->aliases = $config->getAliases();
     $this->config = $config;
     $this->application = $application;
     $this->parentCommand = $parentCommand;
     $this->subCommands = new CommandCollection();
     $this->namedSubCommands = new CommandCollection();
     $this->defaultSubCommands = new CommandCollection();
     $this->argsFormat = $config->buildArgsFormat($this->getBaseFormat());
     $this->dispatcher = $application ? $application->getConfig()->getEventDispatcher() : null;
     foreach ($config->getSubCommandConfigs() as $subConfig) {
         $this->addSubCommand($subConfig);
     }
 }