Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[WIP] [Console] Added Console arguments documentation #3744

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

Closed
wants to merge 2 commits into from
Closed
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
Next Next commit
Added a little sample on Option uses with "spaces"
  • Loading branch information
mickaelandrieu committed Apr 1, 2014
commit efd2502aa2cdd552f645fbd7aea54b772658abf5
2 changes: 1 addition & 1 deletion 2 components/console/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ declare a one-letter shortcut that you can call with a single dash like
.. tip::

It is also possible to make an option *optionally* accept a value (so that
``--yell`` or ``--yell=loud`` work). Options can also be configured to
``--yell`` or ``--yell=loud`` or ``--yell loud`` work). Options can also be configured to
Copy link
Member

Choose a reason for hiding this comment

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

I don't think that this does always work. If the value for the --yell option is optional loud would be treated as an argument, won'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.

no, it will be treated as the value being provided

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does : symfony/symfony#10603 (comment)

It's a little bit weird indeed.

Copy link
Member

Choose a reason for hiding this comment

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

Weird. But if it is intended.

Copy link
Member

Choose a reason for hiding this comment

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

The behaviour is following the docopt standards.

Assume the following InputDefinition:

new InputDefinition(array(
    new InputOption('foo', 'f'),
    new InputOption('bar', 'b', InputOption::VALUE_REQUIRED),
    new InputOption('cat', 'c', InputOption::VALUE_OPTIONAL),
));

The behaviour is:

Input Values
--bar=Hello foo = false, bar = "Hello"
--bar Hello foo = false, bar = "Hello"
-b Hello foo = false, bar = "Hello"
-b=Hello foo = false, bar = "=Hello"
-bHello foo = false, bar = "Hello"
-fbHello foo = true, bar = "Hello"
-fcHello -b World foo = true, bar = "World", cat = "Hello"
-cfHello -b World foo = false, bar = "World", cat = "fHello"
-cbHello cat = "bHello", bar = null

Now, assume there is also an optional argument in the input definition:

new InputDefinition(array(
    // ...
    new InputArgument('qux', InputArgument::OPTIONAL),
));

The behaviour now:

Input Values
--bar Hello bar = "Hello", qux = null
--bar Hello World bar = "Hello", qux = "World"
--bar Hello --cat World bar = "Hello", cat = "World", qux = null
--bar Hello --cat -- World bar = "Hello", cat = null, qux = "World"
-b Hello -c World bar = "Hello", cat = "World", qux = null

The fourth example shows the special -- seperator which -as you can read in docopt- seperates the options from the arguments. By that, World is no longer interpreted as a value of the cat option (which has an optional value), but as the value for the argument.

accept an array of values.

For example, add a new option to the command that can be used to specify
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.