Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion system/CLI/CommandLineParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ private function parseTokens(array $tokens): void
$name = ltrim($token, '-');
$value = null;

if (isset($tokens[$index + 1]) && ! str_starts_with($tokens[$index + 1], '-')) {
if (str_contains($name, '=')) {
[$name, $value] = explode('=', $name, 2);
} elseif (isset($tokens[$index + 1]) && ! str_starts_with($tokens[$index + 1], '-')) {
$value = $tokens[$index + 1];

$optionValue = true;
Expand Down
18 changes: 18 additions & 0 deletions tests/system/CLI/CommandLineParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,23 @@ public static function provideParseCommand(): iterable
['b', 'c', 'd'],
[],
];

yield 'options with equals sign' => [
['--key=value', '--foo='],
[],
['key' => 'value', 'foo' => ''],
];

yield 'options with equals sign and double hyphen' => [
['--key=value', '--foo=', 'bar', '--', 'b', 'c', 'd'],
['bar', 'b', 'c', 'd'],
['key' => 'value', 'foo' => ''],
];

yield 'mixed options with and without equals sign' => [
['--key=value', '--foo', 'bar', '--', 'b', 'c', 'd'],
['b', 'c', 'd'],
['key' => 'value', 'foo' => 'bar'],
];
}
}
4 changes: 4 additions & 0 deletions user_guide_src/source/changelogs/v4.8.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ Commands

- ``CLI`` now supports the ``--`` separator to mean that what follows are arguments, not options. This allows you to have arguments that start with ``-`` without them being treated as options.
For example: ``spark my:command -- --myarg`` will pass ``--myarg`` as an argument instead of an option.
- ``CLI`` now supports options with values specified using an equals sign (e.g., ``--option=value``) in addition to the existing space-separated syntax (e.g., ``--option value``).
This provides more flexibility in how you can pass options to commands.

Testing
=======
Expand Down Expand Up @@ -197,6 +199,8 @@ HTTP
Consequently, ``CURLRequest``'s ``$config`` parameter is unused and will be removed in a future release.
- ``CLIRequest`` now supports the ``--`` separator to mean that what follows are arguments, not options. This allows you to have arguments that start with ``-`` without them being treated as options.
For example: ``php index.php command -- --myarg`` will pass ``--myarg`` as an argument instead of an option.
- ``CLIRequest`` now supports options with values specified using an equals sign (e.g., ``--option=value``) in addition to the existing space-separated syntax (e.g., ``--option value``).
This provides more flexibility in how you can pass options to CLI requests.

Validation
==========
Expand Down
Loading