feat: add support for parsing array options#10079
feat: add support for parsing array options#10079paulbalandan wants to merge 3 commits intocodeigniter4:4.8from
Conversation
a590a06 to
cebbe5a
Compare
cebbe5a to
c7d0aae
Compare
michalsn
left a comment
There was a problem hiding this comment.
The array options feature makes sense, but I'm worried about changing getOption() to sometimes return an array. Existing commands treat it as a scalar/flag accessor.
What do you think about keeping getOption() returning a single value, with a defined rule like "last value wins", and adding a separate method to retrieve all values for repeated options?
That would keep existing code safe while still supporting the new feature.
|
@michalsn, Illogical. Relying on the last key has no order. The array seems like a sure change. We have already created BC, so compatibility will be broken. In this case, for major changes, you already need to have a branch of ~10.x, as many major fixes have been made. Alternatively, you should update the contribution rules and specify that the minor branch may contain new features and BC. Has phpstan got new rules? A lot of mistakes |
CLI arguments absolutely have order.
My main concern is that changing But as always, I'm not gonna be stubborn. If the majority is okay with this, let's proceed.
Yes, I haven't had time to investigate, maybe on the weekend. |
|
I understand what you're talking about. In such cases, yes, the latter value looks acceptable. About the order. I mean, if we select the last value, will the |
|
Yes, in the first case you end up with This is natural: each occurrence overwrites the previous one. If the command isn't meant to handle arrays, If we want repeated parameters, |
|
Should the behavior of getOption also be applied to |
35ef523 to
d546783
Compare
Yes, I think so. If |
d546783 to
1ccc48b
Compare
|
We have some inconsistencies in handling options. The thing is that now:
Do you agree that this test should pass? public function testParseCommandRepeatedFlagOption(): void
{
service('superglobals')->setServer('argv', [
'ignored',
'b',
'--p1',
'--p2',
'--p2',
]);
CLI::init();
$this->assertSame(['p1' => null, 'p2' => [null, null]], CLI::getOptions());
$this->assertTrue(CLI::getOption('p1'));
$this->assertSame(true, CLI::getRawOption('p1'));
$this->assertSame([true, true], CLI::getRawOption('p2'));
$this->assertTrue(CLI::getOption('p2'));
$this->assertSame('-p1 -p2 -p2 ', CLI::getOptionString());
$this->assertSame('--p1 --p2 --p2', CLI::getOptionString(true, true));
$this->assertSame(['b'], CLI::getSegments());
} |
|
I think it should still remain as |
michalsn
left a comment
There was a problem hiding this comment.
Other than these two, it looks good.
931e621 to
335033a
Compare
Co-authored-by: Michal Sniatala <michal@sniatala.pl>
335033a to
b67b8b0
Compare
Description
Support parsing
--option=foo --option=barinto['option' => ['foo', 'bar']].Checklist: