Webmozart\Console\Api\Config\ApplicationConfig::beginCommand PHP Method

beginCommand() public method

The configuration of the command is returned by this method. You can use the fluent interface to configure the sub-command before jumping back to this configuration with {@link CommandConfig::end()}: php protected function configure() { $this ->setName('server') ->setDescription('List and manage servers') ->beginCommand('add') ->setDescription('Add a server') ->addArgument('host', Argument::REQUIRED) ->addOption('port', 'p', Option::VALUE_OPTIONAL, null, 80) ->end() ... ; }
See also: editCommand()
public beginCommand ( string $name ) : CommandConfig
$name string The name of the command.
return CommandConfig The command configuration.
    public function beginCommand($name)
    {
        $commandConfig = new CommandConfig($name, $this);
        // The name is dynamic, so don't store by name
        $this->commandConfigs[] = $commandConfig;
        return $commandConfig;
    }

Usage Example

Ejemplo n.º 1
0
 public static function addConfiguration(ApplicationConfig $config, AssetPlugin $plugin)
 {
     $config->beginCommand('asset')->setDescription('Manage web assets')->setHandler(function () use($plugin) {
         return new AssetCommandHandler($plugin->getAssetManager(), $plugin->getInstallationManager(), $plugin->getInstallTargetManager());
     })->beginSubCommand('map')->addArgument('path', Argument::REQUIRED, 'The resource path')->addArgument('web-path', Argument::REQUIRED, 'The path in the web directory')->addOption('target', 't', Option::REQUIRED_VALUE | Option::PREFER_LONG_NAME, 'The name of the installation target', InstallTarget::DEFAULT_TARGET)->addOption('force', 'f', Option::NO_VALUE, 'Map even if the target does not exist')->setHandlerMethod('handleMap')->end()->beginSubCommand('update')->addArgument('uuid', Argument::REQUIRED, 'The UUID (prefix) of the mapping')->addOption('path', null, Option::REQUIRED_VALUE, 'The resource path')->addOption('web-path', null, Option::REQUIRED_VALUE, 'The path in the web directory')->addOption('target', 't', Option::REQUIRED_VALUE | Option::PREFER_LONG_NAME, 'The name of the installation target', InstallTarget::DEFAULT_TARGET)->addOption('force', 'f', Option::NO_VALUE, 'Update even if the target does not exist')->setHandlerMethod('handleUpdate')->end()->beginSubCommand('remove')->addArgument('uuid', Argument::REQUIRED, 'The UUID (prefix) of the mapping')->setHandlerMethod('handleRemove')->end()->beginSubCommand('list')->markDefault()->setHandlerMethod('handleList')->end()->beginSubCommand('install')->addArgument('target', Argument::OPTIONAL, 'The target to install. By default, all targets are installed')->setHandlerMethod('handleInstall')->end()->end()->beginCommand('target')->setDescription('Manage the install targets of your web resources')->setHandler(function () use($plugin) {
         return new TargetCommandHandler($plugin->getInstallTargetManager());
     })->beginSubCommand('list')->markDefault()->setHandlerMethod('handleList')->end()->beginSubCommand('add')->addArgument('name', Argument::REQUIRED, 'The name of the added target')->addArgument('location', Argument::REQUIRED, 'The location where the web resources are installed')->addOption('installer', null, Option::REQUIRED_VALUE, 'The name of the used installer', 'symlink')->addOption('url-format', null, Option::REQUIRED_VALUE, 'The format of the generated resource URLs', InstallTarget::DEFAULT_URL_FORMAT)->addOption('param', null, Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'Additional parameters to store with the target')->setHandlerMethod('handleAdd')->end()->beginSubCommand('update')->addArgument('name', Argument::REQUIRED, 'The name of the updated target')->addOption('location', null, Option::REQUIRED_VALUE, 'The location where the web resources are installed')->addOption('installer', null, Option::REQUIRED_VALUE, 'The name of the used installer', 'symlink')->addOption('url-format', null, Option::REQUIRED_VALUE, 'The format of the generated resource URLs', InstallTarget::DEFAULT_URL_FORMAT)->addOption('param', null, Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'Additional parameters to store with the target')->addOption('unset-param', null, Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'Parameters to remove from the target')->setHandlerMethod('handleUpdate')->end()->beginSubCommand('remove')->addArgument('name', Argument::REQUIRED, 'The name of the target to remove')->setHandlerMethod('handleRemove')->end()->beginSubCommand('set-default')->addArgument('name', Argument::REQUIRED, 'The name of the default target')->setHandlerMethod('handleSetDefault')->end()->beginSubCommand('get-default')->setHandlerMethod('handleGetDefault')->end()->end()->beginCommand('installer')->setDescription('Manage the installers used to install web resources')->setHandler(function () use($plugin) {
         return new InstallerCommandHandler($plugin->getInstallerManager());
     })->beginSubCommand('list')->markDefault()->addOption('long', 'l', Option::NO_VALUE, 'Print the fully-qualified class name')->setHandlerMethod('handleList')->end()->beginSubCommand('add')->addArgument('name', Argument::REQUIRED, 'The name of the installer')->addArgument('class', Argument::REQUIRED, 'The fully-qualified class name of the installer')->addOption('description', null, Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'The description of the installer')->addOption('param', null, Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'Additional installer parameters')->setHandlerMethod('handleAdd')->end()->beginSubCommand('remove')->addArgument('name', Argument::REQUIRED, 'The name of the installer to remove')->setHandlerMethod('handleRemove')->end()->end();
 }
All Usage Examples Of Webmozart\Console\Api\Config\ApplicationConfig::beginCommand