Skip to content

Commit 1636bce

Browse files
committed
up: update flags parse option logic
1 parent 6628805 commit 1636bce

File tree

4 files changed

+12
-15
lines changed

4 files changed

+12
-15
lines changed

.github/changelog.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ filters:
2424
rules:
2525
- name: Refactor
2626
start_withs: [refactor, break]
27-
contains: ['refactor:']
27+
contains: ['refactor:', 'break:']
2828
- name: Fixed
2929
start_withs: [fix]
3030
contains: ['fix:']
3131
- name: Feature
3232
start_withs: [feat, new]
33-
contains: [feature]
33+
contains: ['feat:', 'new:']
3434
- name: Update
35-
start_withs: [update, 'up:']
36-
contains: []
35+
start_withs: [up]
36+
contains: ['update:', 'up:']

example/clicmd.php

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
// or use property
3333
// $cmd->arguments = [...];
34+
// $cmd->getFlags()->setExample($example);
3435
})
3536
->withArguments([
3637
'arg1' => 'this is arg1, is string'

src/CliCmd.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
class CliCmd
2222
{
2323
use AutoConfigTrait {
24-
__construct as supper;
24+
AutoConfigTrait::__construct as supper;
2525
}
2626

2727
public string $name = '';

src/Flags.php

+6-10
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use function sprintf;
2828
use function str_split;
2929
use function strlen;
30+
use function strpos;
3031
use function substr;
3132

3233
/**
@@ -216,16 +217,11 @@ protected function parseOneOption(): array
216217

217218
$value = '';
218219
$hasVal = false;
219-
for ($i = 0; $i < $optLen; $i++) {
220-
if ($name[$i] === '=') {
221-
$hasVal = true;
222-
$name = substr($name, 0, $i);
223-
224-
// fix: `--name=` no value string.
225-
if ($i + 1 < $optLen) {
226-
$value = substr($name, $i + 1);
227-
}
228-
}
220+
$eqPos = strpos($name, '=');
221+
if ($eqPos > 0) {
222+
$hasVal = true;
223+
$value = substr($name, $eqPos + 1);
224+
$name = substr($name, 0, $eqPos);
229225
}
230226

231227
$rName = $this->resolveAlias($name);

0 commit comments

Comments
 (0)