Skip to content

Commit

Permalink
up: update flags parse option logic
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Aug 6, 2022
1 parent 6628805 commit 1636bce
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
8 changes: 4 additions & 4 deletions .github/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ filters:
rules:
- name: Refactor
start_withs: [refactor, break]
contains: ['refactor:']
contains: ['refactor:', 'break:']
- name: Fixed
start_withs: [fix]
contains: ['fix:']
- name: Feature
start_withs: [feat, new]
contains: [feature]
contains: ['feat:', 'new:']
- name: Update
start_withs: [update, 'up:']
contains: []
start_withs: [up]
contains: ['update:', 'up:']
1 change: 1 addition & 0 deletions example/clicmd.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

// or use property
// $cmd->arguments = [...];
// $cmd->getFlags()->setExample($example);
})
->withArguments([
'arg1' => 'this is arg1, is string'
Expand Down
2 changes: 1 addition & 1 deletion src/CliCmd.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class CliCmd
{
use AutoConfigTrait {
__construct as supper;
AutoConfigTrait::__construct as supper;
}

public string $name = '';
Expand Down
16 changes: 6 additions & 10 deletions src/Flags.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use function sprintf;
use function str_split;
use function strlen;
use function strpos;
use function substr;

/**
Expand Down Expand Up @@ -216,16 +217,11 @@ protected function parseOneOption(): array

$value = '';
$hasVal = false;
for ($i = 0; $i < $optLen; $i++) {
if ($name[$i] === '=') {
$hasVal = true;
$name = substr($name, 0, $i);

// fix: `--name=` no value string.
if ($i + 1 < $optLen) {
$value = substr($name, $i + 1);
}
}
$eqPos = strpos($name, '=');
if ($eqPos > 0) {
$hasVal = true;
$value = substr($name, $eqPos + 1);
$name = substr($name, 0, $eqPos);
}

$rName = $this->resolveAlias($name);
Expand Down

0 comments on commit 1636bce

Please sign in to comment.