Skip to content

Negative argument values and optional variadic arguments / options. #93

Open
@shlomohass

Description

@shlomohass

Hi,
First and foremost, thank you for this fantastic project! While there are others out there, I really like this one since it's small, light, simple, and very flexible.

I am having trouble with negative values:

# cmd <offset> --reduce 
$ cmd  -20 --reduce -4 # fails as it parses -20 to -2 -0 and -4 as an option name.

Usually, in some CLI programs, something like this would be evaluated correctly:

$ cmd  "-20" --reduce "-4" # same issue
$ cmd "-20" --reduce=-4 # this one partially works 

It seems that currently, php-cli doesn't support direct negative values unless I'm missing something (please correct me if I'm wrong).

I modified the Normalizer and the Parser to support that if this is truly an issue let me know, and I can create a pull request.

Also, as an artifact, now a syntax as follows is easily implemented:

# cmd <name> [counted...] --variadic [values...] --another <values...>
$ cmd john [12 45 87] --variadic [ 15 20 65 ] --another 98 65 45
# Square brackets act like group boundaries for "in the middle" variadic arguments.
# Still the last variadic argument, without square brackets, functions as normal.

I think it's Cool... and very useful.

Let me know if that's an acceptable improvement

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions