Skip to content

Commit 148d8db

Browse files
committed
fix: binding args error on not provide
1 parent aac5e91 commit 148d8db

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/Flags.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -386,13 +386,16 @@ public function bindingArguments(): self
386386

387387
// collect argument values
388388
foreach ($this->arguments as $index => $arg) {
389-
if (!isset($args[$index]) && $arg->isRequired()) {
390-
$mark = $arg->getNameMark();
391-
throw new FlagException("flag argument $mark is required");
389+
if (!isset($args[$index])) {
390+
if ($arg->isRequired()) {
391+
$mark = $arg->getNameMark();
392+
throw new FlagException("flag argument $mark is required");
393+
}
394+
continue;
392395
}
393396

394397
if ($arg->isArray()) {
395-
// collect remain args
398+
// collect all remain args
396399
foreach ($args as $value) {
397400
$arg->setValue($value);
398401
}
@@ -404,7 +407,7 @@ public function bindingArguments(): self
404407
}
405408

406409
if ($this->strictCheckArgs && $args) {
407-
throw new FlagException(sprintf('unknown arguments (error: "%s").', implode(', ', $args)));
410+
throw new FlagException(sprintf('unknown arguments (error: "%s").', implode(' ', $args)));
408411
}
409412

410413
return $this;

src/SFlags.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use function strpos;
2929
use function substr;
3030
use function trim;
31+
use function vdump;
3132

3233
/**
3334
* Class SFlags
@@ -546,8 +547,11 @@ public function bindingArguments(): void
546547
$required = $define['required'];
547548
$isArray = FlagType::isArray($define['type']);
548549

549-
if ($required && !isset($args[$index])) {
550-
throw new FlagException("flag argument $mark is required");
550+
if (!isset($args[$index])) {
551+
if ($required) {
552+
throw new FlagException("flag argument $mark is required");
553+
}
554+
continue;
551555
}
552556

553557
// collect value

0 commit comments

Comments
 (0)