This class is a container for {@link CommandName}, {@link CommandOption},
{@link Option} and {@link Argument} objects. The format is used to interpret
a given {@link RawArgs} instance.
You can pass the options and arguments to the constructor of the class:
php
$format = new ArgsFormat(array(
new CommandName('server'),
new CommandName('add'),
new Argument('host', Argument::REQUIRED),
new Option('port', 'p', Option::VALUE_OPTIONAL, null, 80),
));
The previous example configures a command that can be called like this:
$ console server add localhost
$ console server add localhost --port 8080
If the "add" command should be called via an option, change the format to:
php
$format = new ArgsFormat(array(
new CommandName('server'),
new CommandOption('add', 'a'),
new Argument('host', Argument::REQUIRED),
new Option('port', 'p', Option::VALUE_OPTIONAL, null, 80),
));
The command is then called like this:
$ console server --add localhost
$ console server --add localhost --port 8080
The format is immutable after its construction. This is necessary to maintain
consistency when one format inherits from another. For example, adding a
required argument to the base format of a format that already contains
optional arguments is an illegal operation that cannot be prevented if the
formats are mutable.
If you want to create a format stepwisely, use an {@link ArgsFormatBuilder}.
If multiple formats share a common set of options and arguments, extract
these options and arguments into a base format and let the other formats
inherit from this base format:
php
$baseFormat = new ArgsFormat(array(
new Option('verbose', 'v'),
));
$format = new ArgsFormat(array(
new CommandName('server'),
new CommandName('add'),
new Argument('host', Argument::REQUIRED),
new Option('port', 'p', Option::VALUE_OPTIONAL, null, 80),
), $baseFormat);