Skip to content

Commit 52d1b32

Browse files
committed
fix some error, add more methods for use flags
1 parent 03e3331 commit 52d1b32

File tree

5 files changed

+34
-7
lines changed

5 files changed

+34
-7
lines changed

src/Concern/HelperRenderTrait.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ protected function doBuildHelp(array $argDefines, array $optDefines, bool $withC
123123
if ($lines) {
124124
$indent = Str::repeat(' ', $nameLen);
125125
foreach ($lines as $line) {
126-
$buf->writef(" %s%s\n", $indent, $line);
126+
$buf->writef(" %s%s\n", $indent, $line);
127127
}
128128
}
129129
}
@@ -156,7 +156,7 @@ protected function doBuildHelp(array $argDefines, array $optDefines, bool $withC
156156
if ($lines) {
157157
$indent = Str::repeat(' ', $nameLen);
158158
foreach ($lines as $line) {
159-
$buf->writef(" %s%s\n", $indent, $line);
159+
$buf->writef(" %s%s\n", $indent, $line);
160160
}
161161
}
162162
}
@@ -387,6 +387,14 @@ public function getMoreHelp()
387387
return $this->moreHelp;
388388
}
389389

390+
/**
391+
* @param array|string|null $moreHelp
392+
*/
393+
public function setHelp($moreHelp): void
394+
{
395+
$this->setMoreHelp($moreHelp);
396+
}
397+
390398
/**
391399
* @param array|string|null $moreHelp
392400
*/

src/Concern/RuleParserTrait.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,6 @@ protected function parseRule($rule, string $name = '', int $index = 0, bool $isO
248248

249249
// save alias
250250
$item['shorts'] = $shorts ?: $shortsFromRule;
251-
if ($item['required']) {
252-
$this->requiredOpts[] = $name;
253-
}
254251
} else {
255252
$item['index'] = $index;
256253
}

src/Flags.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ public function bindingArguments(): self
410410
throw new FlagException(sprintf('unknown arguments (error: "%s").', implode(' ', $args)));
411411
}
412412

413+
$this->remainArgs = $args;
413414
return $this;
414415
}
415416

src/FlagsParser.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,19 @@ abstract class FlagsParser implements ParserInterface
9090
protected $flags = [];
9191

9292
/**
93-
* The remaining raw args, after option parsed from {@see $rawFlags}
93+
* The remaining raw args, after option parsed from {@see $flags}
9494
*
9595
* @var string[]
9696
*/
9797
protected $rawArgs = [];
9898

99+
/**
100+
* The overage raw args, after argument parsed from {@see $rawArgs}
101+
*
102+
* @var string[]
103+
*/
104+
protected $remainArgs = [];
105+
99106
/**
100107
* The required option names.
101108
*
@@ -416,6 +423,14 @@ public function getRawArgs(): array
416423
return $this->rawArgs;
417424
}
418425

426+
/**
427+
* @return string[]
428+
*/
429+
public function getRemainArgs(): array
430+
{
431+
return $this->remainArgs;
432+
}
433+
419434
/**
420435
* @return string
421436
*/

src/SFlags.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,8 @@ public function bindingArguments(): void
572572
if ($this->strictMatchArgs && $args) {
573573
throw new FlagException(sprintf('unknown arguments (error: "%s").', implode(', ', $args)));
574574
}
575+
576+
$this->remainArgs = $args;
575577
}
576578

577579
/**
@@ -636,7 +638,7 @@ protected function checkDefine(array $define, string $mark, string $kind = self:
636638
$name = $define['name'];
637639

638640
if ($this->isLocked()) {
639-
throw new FlagException("flags has been locked, cannot add $kind");
641+
throw new FlagException("flags has been locked, cannot add $kind($name)");
640642
}
641643

642644
if (isset($this->optDefines[$name])) {
@@ -681,6 +683,10 @@ protected function addOptDefine(array $define): void
681683
$this->opts[$name] = $define['default'] = $default;
682684
}
683685

686+
if ($define['required']) {
687+
$this->requiredOpts[] = $name;
688+
}
689+
684690
// support read value from ENV var
685691
if ($define['envVar'] && ($envVal = OS::getEnvVal($define['envVar']))) {
686692
$this->opts[$name] = FlagType::fmtBasicTypeValue($type, $envVal);

0 commit comments

Comments
 (0)