Skip to content

feat: space separated option values - #73

Merged
HafizMMoaz merged 1 commit into
mainfrom
feat/issue-48-space-separated-values
Sep 7, 2026
Merged

feat: space separated option values#73
HafizMMoaz merged 1 commit into
mainfrom
feat/issue-48-space-separated-values

Conversation

@HafizMMoaz

Copy link
Copy Markdown
Member

Closes #48.

-o value and --opt value now carry a value, next to the --opt=value form that already worked.

How it works

The option definitions decide it: an option a command declares in $optionDefinitions with a type other than flag takes the next token as its value, when that token is not itself an option or the -- marker. Options with no definition keep the old behaviour, so -abc still expands to three boolean flags and nothing that works today changes.

Since the definitions belong to the command, the parse happens twice: prepare() parses as before and keeps the tokens, then dispatch() parses them again once the command is resolved. The console wide options are re-applied after that second pass, so --quiet and --no-ansi keep working.

In a short group only the last option can take a value, as in -vf config.php, which is what getopt style parsers do.

Negative numbers

The edge case from the issue is fixed too: a token that is numeric after the dash, like -5 or -1.5, is an argument now instead of a set of boolean options, so it no longer needs the -- marker. It is also accepted as an option value, as in --offset -5.

Tests

tests/OptionValueTest.php covers the short and long form, the group form, the negative numbers, and the cases that must not change: undefined options, flag options, an option followed by another option, and the -- marker. Full suite is green (128 tests), PHPStan and the coding standard are clean.

An option a command declares in its option definitions with a type other
than "flag" now takes the next token as its value, so -o value and
--opt value work next to --opt=value. Options with no definition keep
returning true and leave the next token in the arguments.

The tokens are kept after prepare() so the options can be parsed again
in dispatch(), once the command and its definitions are known.

A token that is a negative number, like -5, is now an argument instead
of a set of boolean options, so it no longer needs the -- marker.
@HafizMMoaz
HafizMMoaz merged commit 2f640d6 into main Sep 7, 2026
4 checks passed
@HafizMMoaz
HafizMMoaz deleted the feat/issue-48-space-separated-values branch September 7, 2026 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant