Skip to content

Commit ac5261f

Browse files
Minor bugfix where usage for commands was always called.
Signed-off-by: Johannes Tegnér <johannes@jitesoft.com>
1 parent b824065 commit ac5261f

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

src/Arguments/Parser.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,26 +62,26 @@ public static function parse(array $argv = null): array {
6262
$opt = true;
6363
}
6464

65-
if ($opt) {
66-
if (str_contains($entry, '=')) {
67-
$split = explode('=', $entry);
68-
$opts[trim($split[0], " \t\n\r\0\x0B-")] = trim($split[1]);
69-
} else if ($len > ($i + 1) && !str_starts_with($inArgs[$i + 1], '-')) {
70-
$val = '';
71-
72-
while ($len > ($i + 1) && !str_starts_with($inArgs[$i + 1], '-')) {
73-
$val .= $inArgs[$i + 1] . ' ';
74-
$i++;
75-
}
76-
77-
$opts[trim($entry, " \t\n\r\0\x0B-")] = trim($val, " \t\n\r\0\x0B\"");
78-
} else {
79-
$opts[trim($entry, " \t\n\r\0\x0B-")] = null;
80-
}
65+
if (!$opt) {
66+
$args[] = trim($entry, " \t\n\r\0\x0B\"");
8167
continue;
8268
}
8369

84-
$args[] = trim($entry, " \t\n\r\0\x0B\"");
70+
if (str_contains($entry, '=')) {
71+
$split = explode('=', $entry);
72+
$opts[trim($split[0], " \t\n\r\0\x0B-")] = trim($split[1]);
73+
} else if ($len > ($i + 1) && !str_starts_with($inArgs[$i + 1], '-')) {
74+
$val = '';
75+
76+
while ($len > ($i + 1) && !str_starts_with($inArgs[$i + 1], '-')) {
77+
$val .= $inArgs[$i + 1] . ' ';
78+
$i++;
79+
}
80+
81+
$opts[trim($entry, " \t\n\r\0\x0B-")] = trim($val, " \t\n\r\0\x0B\"");
82+
} else {
83+
$opts[trim($entry, " \t\n\r\0\x0B-")] = null;
84+
}
8585
}
8686

8787
self::$parsed = ['command' => $command, 'arguments' => $args, 'options' => $opts];

src/Kernel.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,15 @@ public function process(array $argv = null): void {
6767
$parsed = Parser::parse($argv);
6868

6969
$command = $this->manager->getCommand();
70+
7071
if ($command === null) {
7172
$this->manager->usage();
7273
return;
7374
}
7475

7576
try {
7677
foreach ($parsed as $key => $value) {
77-
if (strtolower($key) === 'help' || strtolower('h')) {
78+
if (strtolower($key) === 'help' || strtolower($key) === 'h') {
7879
$this->manager->usage($command);
7980
return;
8081
}

0 commit comments

Comments
 (0)