Skip to content

Bare double dash (--) not interpreted as end of named arguments #5209

@nickdaugherty

Description

@nickdaugherty

Bug Report

Describe the current, buggy behavior

The "bare double dash", or "--" is often used in unix commands to signify the end of named arguments, after which all arguments are treated as positional.

The first -- argument that is not an option-argument should be accepted as a delimiter indicating the end of options. Any following arguments should be treated as operands, even if they begin with the '-' character.

http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html#tag_12_02

However, WP-CLI doesn't seem to handle the double dash correctly - instead, it treats it as a positional argument and still parses subsequent args as named.

Describe how other contributors can replicate this bug

Try these two commands, which would be expected to have distinct results:

$ wp option get home --require=/blah
Error: Required file 'blah' doesn't exist (from runtime argument).
$ wp option get home -- --require=/blah
Error: Required file 'blah' doesn't exist (from runtime argument).

Or this one, which should have worked:

$ wp option -- get home
Error: '--' is not a registered subcommand of 'option'. See 'wp help option' for available subcommands.

Describe what you expect as the correct outcome

When running $ wp option get home -- --require=/blah, I would have expected the --require parameter to be treated as a positional argument instead of a being parsed into a the named global parameter.

With $ wp option -- get home, The double dash should have been ignored, resulting in effectively wp option get home being run.

Let us know what environment you are running this on

OS:	Linux 4.9.125-linuxkit #1 SMP Fri Sep 7 08:20:28 UTC 2018 x86_64
Shell:
PHP binary:	/usr/local/bin/php
PHP version:	7.2.14
php.ini used:	/usr/local/etc/php/php.ini
WP-CLI root dir:	phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir:	phar://wp-cli.phar/vendor
WP_CLI phar path:	/var/www/html
WP-CLI packages dir:
WP-CLI global config:
WP-CLI project config:	/var/www/html/wp-cli.local.yml
WP-CLI version:	2.2.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions