Skip to content

added example on how to use InputArgument::IS_ARRAY, added overview of a... #2689

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 4, 2013
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions components/console/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,44 @@ The command can now be used in either of the following ways:
$ app/console demo:greet Fabien
$ app/console demo:greet Fabien Potencier

It is also possible to let an argument take a list of values (imagine you want
to greet all your friends). For this it must be specified at the end of the
argument list::

$this
// ...
->addArgument(
'names',
InputArgument::IS_ARRAY,
'Who do you want to greet (separate multiple names with a space)?'
);

You can now access the ``names`` argument as an array::

if ($names = $input->getArgument('names')) {
$text .= ''.implode(', ', $names);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

''. is quite useless...

}

There are 3 argument variants you can use:

=========================== =================================================================================================
Option Value
=========================== =================================================================================================
InputArgument::REQUIRED The argument is required
InputArgument::OPTIONAL The argument is optional and therefore can be omitted
InputArgument::IS_ARRAY Allows to specify an indefinite number of arguments, must be used at the end of the argument list
=========================== =================================================================================================

You can combine IS_ARRAY with REQUIRED and OPTIONAL like this::
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should put those constants in literals

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same applies to the constants in the options section, doesn't it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes


$this
// ...
->addArgument(
'names',
InputArgument::IS_ARRAY | InputArgument::REQUIRED,
'Who do you want to greet (separate multiple names with a space)?'
);

Using Command Options
---------------------

Expand Down