Skip to content

Commit 4c95fda

Browse files
committed
minor #9387 Clarify how to use short options with values. (greg-1-anderson, javiereguiluz)
This PR was submitted for the master branch but it was merged into the 2.7 branch instead (closes #9387). Discussion ---------- Clarify how to use short options with values. Adds a brief description of the correct syntax for short options that take values. Related to symfony/symfony#26378 Commits ------- 926461a Removed a duplicated content 194e541 Minor tweaks 2eddcf1 Clarify Symfony Console option conventions 2cf4122 Wrap long lines f4b77be Clarify how to use short options with values.
2 parents 60e0138 + 926461a commit 4c95fda

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

console/input.rst

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ flag:
174174
1
175175
);
176176

177+
Note that to comply with the `docopt standard`_, long options can specify their
178+
values after a white space or an ``=`` sign (e.g. ``--iterations 5`` or
179+
``--iterations=5``), but short options can only use white spaces or no
180+
separation at all (e.g. ``-i 5`` or ``-i5``).
181+
177182
There are four option variants you can use:
178183

179184
``InputOption::VALUE_IS_ARRAY``
@@ -184,8 +189,8 @@ There are four option variants you can use:
184189
behavior of options;
185190

186191
``InputOption::VALUE_REQUIRED``
187-
This value is required (e.g. ``--iterations=5``), the option itself is
188-
still optional;
192+
This value is required (e.g. ``--iterations=5`` or ``-i5``), the option
193+
itself is still optional;
189194

190195
``InputOption::VALUE_OPTIONAL``
191196
This option may or may not have a value (e.g. ``--yell`` or
@@ -215,3 +220,14 @@ You can combine ``VALUE_IS_ARRAY`` with ``VALUE_REQUIRED`` or
215220
Similarly, due to a PHP limitation, there is no way to pass an empty string
216221
as the value of an option. In ``command --prefix`` and ``command --prefix=''``
217222
cases, the value of the ``prefix`` option will be ``null``.
223+
224+
.. caution::
225+
226+
While it is possible to separate an option from its value with a white space,
227+
using this form leads to an ambiguity should the option appear before the
228+
command name. For example, ``php bin/console --iterations 5 app:greet Fabien``
229+
is ambiguous; Symfony would interpret ``5`` as the command name. To avoid
230+
this situation, always place options after the command name, or avoid using
231+
a space to separate the option name from its value.
232+
233+
.. _`docopt standard`: http://docopt.org/

0 commit comments

Comments
 (0)