InputOption example


        return $this->singleCommand ? $this->defaultCommand : $input->getFirstArgument();
    }

    /** * Gets the default input definition. */
    protected function getDefaultInputDefinition(): InputDefinition
    {
        return new InputDefinition([
            new InputArgument('command', InputArgument::REQUIRED, 'The command to execute'),
            new InputOption('--help', '-h', InputOption::VALUE_NONE, 'Display help for the given command. When no command is given display help for the <info>'.$this->defaultCommand.'</info> command'),
            new InputOption('--quiet', '-q', InputOption::VALUE_NONE, 'Do not output any message'),
            new InputOption('--verbose', '-v|vv|vvv', InputOption::VALUE_NONE, 'Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug'),
            new InputOption('--version', '-V', InputOption::VALUE_NONE, 'Display this application version'),
            new InputOption('--ansi', '', InputOption::VALUE_NEGATABLE, 'Force (or disable --no-ansi) ANSI output', null),
            new InputOption('--no-interaction', '-n', InputOption::VALUE_NONE, 'Do not ask any interactive question'),
        ]);
    }

    /** * Gets the default commands that should always be available. * * @return Command[] */

        parent::__construct();

        $this->dispatchers = $dispatchers;
    }

    protected function configure(): void
    {
        $this
            ->setDefinition([
                new InputArgument('event', InputArgument::OPTIONAL, 'An event name or a part of the event name'),
                new InputOption('dispatcher', null, InputOption::VALUE_REQUIRED, 'To view events of a specific event dispatcher', self::DEFAULT_DISPATCHER),
                new InputOption('format', null, InputOption::VALUE_REQUIRED, sprintf('The output format ("%s")', implode('", "', $this->getAvailableFormatOptions())), 'txt'),
                new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw description'),
            ])
            ->setHelp(<<<'EOF' The <info>%command.name%</info> command displays all configured listeners: <info>php %command.full_name%</info> To get specific listeners for an event, specify its name: <info>php %command.full_name% kernel.request</info>
parent::__construct();

        $this->router = $router;
        $this->fileLinkFormatter = $fileLinkFormatter;
    }

    protected function configure(): void
    {
        $this
            ->setDefinition([
                new InputArgument('name', InputArgument::OPTIONAL, 'A route name'),
                new InputOption('show-controllers', null, InputOption::VALUE_NONE, 'Show assigned controllers in overview'),
                new InputOption('format', null, InputOption::VALUE_REQUIRED, sprintf('The output format ("%s")', implode('", "', $this->getAvailableFormatOptions())), 'txt'),
                new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw route(s)'),
            ])
            ->setHelp(<<<'EOF' The <info>%command.name%</info> displays the configured routes: <info>php %command.full_name%</info> EOF
            )
        ;
    }
$definition = new InputDefinition();
        $definition->addOption($this->foo);
        $definition->addOption($this->foo2);
    }

    public function testAddDuplicateNegatedOption()
    {
        $this->expectException(\LogicException::class);
        $this->expectExceptionMessage('An option named "no-foo" already exists.');

        $definition = new InputDefinition();
        $definition->addOption(new InputOption('no-foo'));
        $definition->addOption(new InputOption('foo', null, InputOption::VALUE_NEGATABLE));
    }

    public function testAddDuplicateNegatedReverseOption()
    {
        $this->expectException(\LogicException::class);
        $this->expectExceptionMessage('An option named "no-foo" already exists.');

        $definition = new InputDefinition();
        $definition->addOption(new InputOption('foo', null, InputOption::VALUE_NEGATABLE));
        $definition->addOption(new InputOption('no-foo'));
    }
class ListCommand extends Command
{
    /** * @return void */
    protected function configure()
    {
        $this
            ->setName('list')
            ->setDefinition([
                new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name', null, fn () => array_keys((new ApplicationDescription($this->getApplication()))->getNamespaces())),
                new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list'),
                new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (txt, xml, json, or md)', 'txt', fn () => (new DescriptorHelper())->getFormats()),
                new InputOption('short', null, InputOption::VALUE_NONE, 'To skip describing commands\' arguments'),
            ])
            ->setDescription('List commands')
            ->setHelp(<<<'EOF' The <info>%command.name%</info> command lists all commands: <info>%command.full_name%</info> You can also display the commands for a specific namespace: <info>%command.full_name% test</info> You can also output the information in other formats by using the <comment>--format</comment> option: <info>%command.full_name% --format=xml</info> It's also possible to get raw list of commands (useful for embedding command runner): <info>%command.full_name% --raw</info>
$this->messageBus = $messageBus;
        $this->logger = $logger;

        parent::__construct($globalReceiverName$failureTransports$phpSerializer);
    }

    protected function configure(): void
    {
        $this
            ->setDefinition([
                new InputArgument('id', InputArgument::IS_ARRAY, 'Specific message id(s) to retry'),
                new InputOption('force', null, InputOption::VALUE_NONE, 'Force action without confirmation'),
                new InputOption('transport', null, InputOption::VALUE_OPTIONAL, 'Use a specific failure transport', self::DEFAULT_TRANSPORT_OPTION),
            ])
            ->setHelp(<<<'EOF' The <info>%command.name%</info> retries message in the failure transport. <info>php %command.full_name%</info> The command will interactively ask if each message should be retried or discarded. Some transports support retrying a specific message id, which comes from the <info>messenger:failed:show</info> command. <info>php %command.full_name% {id}</info> Or pass multiple ids at once to process multiple messages: <info>php %command.full_name% {id1} {id2} {id3}</info>


    public function run(): int
    {
        if (null === $this->defaultEnv) {
            return $this->application->run($this->input, $this->output);
        }

        $definition = $this->application->getDefinition();

        if (!$definition->hasOption('env') && !$definition->hasOption('e') && !$definition->hasShortcut('e')) {
            $definition->addOption(new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', $this->defaultEnv));
        }

        if (!$definition->hasOption('no-debug')) {
            $definition->addOption(new InputOption('--no-debug', null, InputOption::VALUE_NONE, 'Switches off debug mode.'));
        }

        return $this->application->run($this->input, $this->output);
    }
}
public function __construct(UlidFactory $factory = null)
    {
        $this->factory = $factory ?? new UlidFactory();

        parent::__construct();
    }

    protected function configure(): void
    {
        $this
            ->setDefinition([
                new InputOption('time', null, InputOption::VALUE_REQUIRED, 'The ULID timestamp: a parsable date/time string'),
                new InputOption('count', 'c', InputOption::VALUE_REQUIRED, 'The number of ULID to generate', 1),
                new InputOption('format', 'f', InputOption::VALUE_REQUIRED, sprintf('The ULID output format ("%s")', implode('", "', $this->getAvailableFormatOptions())), 'base32'),
            ])
            ->setHelp(<<<'EOF' The <info>%command.name%</info> command generates a ULID. <info>php %command.full_name%</info> To specify the timestamp: <info>php %command.full_name% --time="2021-02-16 14:09:08"</info> To generate several ULIDs: <info>php %command.full_name% --count=10</info> To output a specific format: <info>php %command.full_name% --format=rfc4122</info>
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputOption;

class CompletionInputTest extends TestCase
{
    /** * @dataProvider provideBindData */
    public function testBind(CompletionInput $input, string $expectedType, ?string $expectedName, string $expectedValue)
    {
        $definition = new InputDefinition([
            new InputOption('with-required-value', 'r', InputOption::VALUE_REQUIRED),
            new InputOption('with-optional-value', 'o', InputOption::VALUE_OPTIONAL),
            new InputOption('without-value', 'n', InputOption::VALUE_NONE),
            new InputArgument('required-arg', InputArgument::REQUIRED),
            new InputArgument('optional-arg', InputArgument::OPTIONAL),
        ]);

        $input->bind($definition);

        $this->assertEquals($expectedType$input->getCompletionType(), 'Unexpected type');
        $this->assertEquals($expectedName$input->getCompletionName(), 'Unexpected name');
        $this->assertEquals($expectedValue$input->getCompletionValue(), 'Unexpected value');
    }
$this->transPaths = $transPaths;
        $this->codePaths = $codePaths;
        $this->enabledLocales = $enabledLocales;
    }

    protected function configure(): void
    {
        $this
            ->setDefinition([
                new InputArgument('locale', InputArgument::REQUIRED, 'The locale'),
                new InputArgument('bundle', InputArgument::OPTIONAL, 'The bundle name or directory where to load the messages'),
                new InputOption('prefix', null, InputOption::VALUE_OPTIONAL, 'Override the default prefix', '__'),
                new InputOption('format', null, InputOption::VALUE_OPTIONAL, 'Override the default output format', 'xlf12'),
                new InputOption('dump-messages', null, InputOption::VALUE_NONE, 'Should the messages be dumped in the console'),
                new InputOption('force', null, InputOption::VALUE_NONE, 'Should the extract be done'),
                new InputOption('clean', null, InputOption::VALUE_NONE, 'Should clean not found messages'),
                new InputOption('domain', null, InputOption::VALUE_OPTIONAL, 'Specify the domain to extract'),
                new InputOption('sort', null, InputOption::VALUE_OPTIONAL, 'Return list of messages sorted alphabetically (only works with --dump-messages)', 'asc'),
                new InputOption('as-tree', null, InputOption::VALUE_OPTIONAL, 'Dump the messages as a tree-like structure: The given value defines the level where to switch to inline YAML'),
            ])
            ->setHelp(<<<'EOF' The <info>%command.name%</info> command extracts translation strings from templates of a given bundle or the default translations directory. It can display them or merge the new ones into the translation files. When new translation strings are found it can automatically add a prefix to the translation message. Example running against a Bundle (AcmeBundle) <info>php %command.full_name% --dump-messages en AcmeBundle</info> <info>php %command.full_name% --force --prefix="new_" fr AcmeBundle</info> Example running against default messages directory <info>php %command.full_name% --dump-messages en</info> <info>php %command.full_name% --force --prefix="new_" fr</info> You can sort the output with the <comment>--sort</> flag: <info>php %command.full_name% --dump-messages --sort=asc en AcmeBundle</info> <info>php %command.full_name% --dump-messages --sort=desc fr</info> You can dump a tree-like structure using the yaml format with <comment>--as-tree</> flag: <info>php %command.full_name% --force --format=yaml --as-tree=3 en AcmeBundle</info>
$this->transPaths = $transPaths;
        $this->codePaths = $codePaths;
        $this->enabledLocales = $enabledLocales;
    }

    protected function configure(): void
    {
        $this
            ->setDefinition([
                new InputArgument('locale', InputArgument::REQUIRED, 'The locale'),
                new InputArgument('bundle', InputArgument::OPTIONAL, 'The bundle name or directory where to load the messages'),
                new InputOption('domain', null, InputOption::VALUE_OPTIONAL, 'The messages domain'),
                new InputOption('only-missing', null, InputOption::VALUE_NONE, 'Display only missing messages'),
                new InputOption('only-unused', null, InputOption::VALUE_NONE, 'Display only unused messages'),
                new InputOption('all', null, InputOption::VALUE_NONE, 'Load messages from all registered bundles'),
            ])
            ->setHelp(<<<'EOF' The <info>%command.name%</info> command helps finding unused or missing translation messages and comparing them with the fallback ones by inspecting the templates and translation files of a given bundle or the default translations directory. You can display information about bundle translations in a specific locale: <info>php %command.full_name% en AcmeDemoBundle</info> You can also specify a translation domain for the search: <info>php %command.full_name% --domain=messages en AcmeDemoBundle</info> You can only display missing messages: <info>php %command.full_name% --only-missing en AcmeDemoBundle</info> You can only display unused messages: <info>php %command.full_name% --only-unused en AcmeDemoBundle</info> You can display information about application translations in a specific locale: <info>php %command.full_name% en</info> You can display information about translations in all registered bundles in a specific locale: <info>php %command.full_name% --all en</info>
public function __construct(UuidFactory $factory = null)
    {
        $this->factory = $factory ?? new UuidFactory();

        parent::__construct();
    }

    protected function configure(): void
    {
        $this
            ->setDefinition([
                new InputOption('time-based', null, InputOption::VALUE_REQUIRED, 'The timestamp, to generate a time-based UUID: a parsable date/time string'),
                new InputOption('node', null, InputOption::VALUE_REQUIRED, 'The UUID whose node part should be used as the node of the generated UUID'),
                new InputOption('name-based', null, InputOption::VALUE_REQUIRED, 'The name, to generate a name-based UUID'),
                new InputOption('namespace', null, InputOption::VALUE_REQUIRED, 'The UUID to use at the namespace for named-based UUIDs, predefined namespaces keywords "dns", "url", "oid" and "x500" are accepted'),
                new InputOption('random-based', null, InputOption::VALUE_NONE, 'To generate a random-based UUID'),
                new InputOption('count', 'c', InputOption::VALUE_REQUIRED, 'The number of UUID to generate', 1),
                new InputOption('format', 'f', InputOption::VALUE_REQUIRED, sprintf('The UUID output format ("%s")', implode('", "', $this->getAvailableFormatOptions())), 'rfc4122'),
            ])
            ->setHelp(<<<'EOF' The <info>%command.name%</info> generates a UUID. <info>php %command.full_name%</info> To generate a time-based UUID: <info>php %command.full_name% --time-based=now</info> To specify a time-based UUID's node: <info>php %command.full_name% --time-based=@1613480254 --node=fb3502dc-137e-4849-8886-ac90d07f64a7</info> To generate a name-based UUID: <info>php %command.full_name% --name-based=foo</info> To specify a name-based UUID's namespace: <info>php %command.full_name% --name-based=bar --namespace=fb3502dc-137e-4849-8886-ac90d07f64a7</info> To generate a random-based UUID: <info>php %command.full_name% --random-based</info> To generate several UUIDs: <info>php %command.full_name% --count=10</info> To output a specific format: <info>php %command.full_name% --format=base58</info>
parent::__construct();

        $this->router = $router;
        $this->expressionLanguageProviders = $expressionLanguageProviders;
    }

    protected function configure(): void
    {
        $this
            ->setDefinition([
                new InputArgument('path_info', InputArgument::REQUIRED, 'A path info'),
                new InputOption('method', null, InputOption::VALUE_REQUIRED, 'Set the HTTP method'),
                new InputOption('scheme', null, InputOption::VALUE_REQUIRED, 'Set the URI scheme (usually http or https)'),
                new InputOption('host', null, InputOption::VALUE_REQUIRED, 'Set the URI host'),
            ])
            ->setHelp(<<<'EOF' The <info>%command.name%</info> shows which routes match a given request and which don't and for what reason: <info>php %command.full_name% /foo</info> or <info>php %command.full_name% /foo --method POST --scheme https --host symfony.com --verbose</info>
class ConfigDebugCommand extends AbstractConfigCommand
{
    protected function configure(): void
    {
        $commentedHelpFormats = array_map(fn ($format) => sprintf('<comment>%s</comment>', $format)$this->getAvailableFormatOptions());
        $helpFormats = implode('", "', $commentedHelpFormats);

        $this
            ->setDefinition([
                new InputArgument('name', InputArgument::OPTIONAL, 'The bundle name or the extension alias'),
                new InputArgument('path', InputArgument::OPTIONAL, 'The configuration option path'),
                new InputOption('resolve-env', null, InputOption::VALUE_NONE, 'Display resolved environment variable values instead of placeholders'),
                new InputOption('format', null, InputOption::VALUE_REQUIRED, sprintf('The output format ("%s")', implode('", "', $this->getAvailableFormatOptions()))class_exists(Yaml::class) ? 'txt' : 'json'),
            ])
            ->setHelp(<<<EOF The <info>%command.name%</info> command dumps the current configuration for an extension/bundle. Either the extension alias or bundle name can be used: <info>php %command.full_name% framework</info> <info>php %command.full_name% FrameworkBundle</info> The <info>--format</info> option specifies the format of the configuration, these are "
public function __construct(CacheWarmerAggregate $cacheWarmer)
    {
        parent::__construct();

        $this->cacheWarmer = $cacheWarmer;
    }

    protected function configure(): void
    {
        $this
            ->setDefinition([
                new InputOption('no-optional-warmers', '', InputOption::VALUE_NONE, 'Skip optional cache warmers (faster)'),
            ])
            ->setHelp(<<<'EOF' The <info>%command.name%</info> command warms up the cache. Before running this command, the cache must be empty. EOF
            )
        ;
    }

    
Home | Imprint | This part of the site doesn't use cookies.