@@ -86,13 +86,16 @@ You can access the ``names`` argument as an array::
8686
8787There are three argument variants you can use:
8888
89- =========================== ===========================================================================================================
90- Mode Value
91- =========================== ===========================================================================================================
92- ``InputArgument::REQUIRED `` The argument is required
93- ``InputArgument::OPTIONAL `` The argument is optional and therefore can be omitted
94- ``InputArgument::IS_ARRAY `` The argument can contain an indefinite number of arguments and must be used at the end of the argument list
95- =========================== ===========================================================================================================
89+ ``InputArgument::REQUIRED ``
90+ The argument is mandatory. The command doesn't run if the argument isn't
91+ provided;
92+
93+ ``InputArgument::OPTIONAL ``
94+ The argument is optional and therefore can be omitted;
95+
96+ ``InputArgument::IS_ARRAY ``
97+ The argument can contain any number of values. For that reason, it must be
98+ used at the end of the argument list
9699
97100You can combine ``IS_ARRAY `` with ``REQUIRED `` and ``OPTIONAL `` like this::
98101
@@ -108,19 +111,9 @@ Using Command Options
108111---------------------
109112
110113Unlike arguments, options are not ordered (meaning you can specify them in any
111- order) and are specified with two dashes (e.g. ``--yell `` - you can also
112- declare a one-letter shortcut that you can call with a single dash like
113- ``-y ``). Options are *always * optional, and can be setup to accept a value
114- (e.g. ``--dir=src ``) or simply as a boolean flag without a value (e.g.
115- ``--yell ``).
116-
117- .. tip ::
118-
119- There is nothing forbidding you to create a command with an option that
120- optionally accepts a value. However, there is no way you can distinguish
121- when the option was used without a value (``command --yell ``) or when it
122- wasn't used at all (``command ``). In both cases, the value retrieved for
123- the option will be ``null ``.
114+ order) and are specified with two dashes (e.g. ``--yell ``). Options are
115+ *always * optional, and can be setup to accept a value (e.g. ``--dir=src ``) or
116+ simply as a boolean flag without a value (e.g. ``--yell ``).
124117
125118For example, add a new option to the command that can be used to specify
126119how many times in a row the message should be printed::
@@ -162,16 +155,33 @@ flag:
162155 $ php app/console app:greet Fabien --yell --iterations=5
163156 $ php app/console app:greet --yell --iterations=5 Fabien
164157
165- There are 4 option variants you can use :
158+ .. tip : :
166159
167- =============================== =====================================================================================
168- Option Value
169- =============================== =====================================================================================
170- ``InputOption::VALUE_IS_ARRAY `` This option accepts multiple values (e.g. ``--dir=/foo --dir=/bar ``)
171- ``InputOption::VALUE_NONE `` Do not accept input for this option (e.g. ``--yell ``)
172- ``InputOption::VALUE_REQUIRED `` This value is required (e.g. ``--iterations=5 ``), the option itself is still optional
173- ``InputOption::VALUE_OPTIONAL `` This option may or may not have a value (e.g. ``--yell `` or ``--yell=loud ``)
174- =============================== =====================================================================================
160+ You can also declare a one-letter shortcut that you can call with a single
161+ dash, like ``-i ``::
162+
163+ $this
164+ // ...
165+ ->addOption(
166+ 'iterations',
167+ 'i',
168+ InputOption::VALUE_REQUIRED,
169+ 'How many times should the message be printed?',
170+ 1
171+ );
172+
173+ There are four option variants you can use:
174+
175+ ``InputOption::VALUE_IS_ARRAY ``
176+ This option accepts multiple values (e.g. ``--dir=/foo --dir=/bar ``);
177+ ``InputOption::VALUE_NONE ``
178+ Do not accept input for this option (e.g. ``--yell ``);
179+ ``InputOption::VALUE_REQUIRED ``
180+ This value is required (e.g. ``--iterations=5 ``), the option itself is
181+ still optional;
182+ ``InputOption::VALUE_OPTIONAL ``
183+ This option may or may not have a value (e.g. ``--yell `` or
184+ ``--yell=loud ``).
175185
176186You can combine ``VALUE_IS_ARRAY `` with ``VALUE_REQUIRED `` or
177187``VALUE_OPTIONAL `` like this::
@@ -185,3 +195,11 @@ You can combine ``VALUE_IS_ARRAY`` with ``VALUE_REQUIRED`` or
185195 'Which colors do you like?',
186196 array('blue', 'red')
187197 );
198+
199+ .. tip ::
200+
201+ There is nothing forbidding you to create a command with an option that
202+ optionally accepts a value. However, there is no way you can distinguish
203+ when the option was used without a value (``command --language ``) or when
204+ it wasn't used at all (``command ``). In both cases, the value retrieved for
205+ the option will be ``null ``.
0 commit comments