Skip to content

Support space separated option values (-o value and --opt value) #48

Description

@HafizMMoaz

Only --opt=value carries a value today. -o value and --opt value put the value into the argument list instead (src/Console.php:427-445):

php app serve -h 0.0.0.0 --port 8080
# options:   h => true, port => true
# arguments: ['0.0.0.0', '8080']

That is the form most CLIs use, the README already tells users it works, and without it a command cannot accept a value under a short name at all.

Since -abc currently expands to three boolean flags, this needs the option definitions to disambiguate: an option declared in $optionDefinitions with a type other than a flag consumes the next token when it is not itself an option. Options with no definition keep the current behaviour, which keeps this backward compatible.

Related edge case worth handling at the same time: a negative number argument is parsed as options today, so php app calc -5 yields ['5' => true] and no arguments. Requiring -- to pass it is a workaround, but a token that is numeric after the dash could reasonably be treated as an argument.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions