@@ -15,10 +15,10 @@ other batch jobs.
15
15
Installation
16
16
------------
17
17
18
- You can install the component in many different ways:
18
+ You can install the component in 2 different ways:
19
19
20
20
* Use the official Git repository (https://github.com/symfony/Console);
21
- * :doc: `Install it via Composer</components/using_components> ` (``symfony/console `` on `Packagist `_).
21
+ * :doc: `Install it via Composer </components/using_components >` (``symfony/console `` on `Packagist `_).
22
22
23
23
.. note ::
24
24
@@ -229,6 +229,50 @@ The command can now be used in either of the following ways:
229
229
$ app/console demo:greet Fabien
230
230
$ app/console demo:greet Fabien Potencier
231
231
232
+ It is also possible to let an argument take a list of values (imagine you want
233
+ to greet all your friends). For this it must be specified at the end of the
234
+ argument list::
235
+
236
+ $this
237
+ // ...
238
+ ->addArgument(
239
+ 'names',
240
+ InputArgument::IS_ARRAY,
241
+ 'Who do you want to greet (separate multiple names with a space)?'
242
+ );
243
+
244
+ To use this, just specify as many names as you want:
245
+
246
+ .. code-block :: bash
247
+
248
+ $ app/console demo:greet Fabien Ryan Bernhard
249
+
250
+ You can access the ``names `` argument as an array::
251
+
252
+ if ($names = $input->getArgument('names')) {
253
+ $text .= ' '.implode(', ', $names);
254
+ }
255
+
256
+ There are 3 argument variants you can use:
257
+
258
+ =========================== ===============================================================================================================
259
+ Option Value
260
+ =========================== ===============================================================================================================
261
+ InputArgument::REQUIRED The argument is required
262
+ InputArgument::OPTIONAL The argument is optional and therefore can be omitted
263
+ InputArgument::IS_ARRAY The argument can can contain an indefinite number of arguments and must be used at the end of the argument list
264
+ =========================== ===============================================================================================================
265
+
266
+ You can combine ``IS_ARRAY `` with ``REQUIRED `` and ``OPTIONAL `` like this::
267
+
268
+ $this
269
+ // ...
270
+ ->addArgument(
271
+ 'names',
272
+ InputArgument::IS_ARRAY | InputArgument::REQUIRED,
273
+ 'Who do you want to greet (separate multiple names with a space)?'
274
+ );
275
+
232
276
Using Command Options
233
277
---------------------
234
278
@@ -297,7 +341,7 @@ InputOption::VALUE_REQUIRED This value is required (e.g. ``--iterations=5``), t
297
341
InputOption::VALUE_OPTIONAL This option may or may not have a value (e.g. ``yell `` or ``yell=loud ``)
298
342
=========================== =====================================================================================
299
343
300
- You can combine VALUE_IS_ARRAY with VALUE_REQUIRED or VALUE_OPTIONAL like this:
344
+ You can combine `` VALUE_IS_ARRAY `` with `` VALUE_REQUIRED `` or `` VALUE_OPTIONAL `` like this:
301
345
302
346
.. code-block :: php
303
347
0 commit comments