Skip to content

Commit 005c0e0

Browse files
committed
up: add more methods for get help data
1 parent 9d8070d commit 005c0e0

File tree

5 files changed

+55
-13
lines changed

5 files changed

+55
-13
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ public const DEFINE_ITEM = [
377377
## Costom Settings
378378

379379
```php
380+
// -------------------- settings for parse option --------------------
380381

381382
/**
382383
* Stop parse option on found first argument.

src/Contract/ParserInterface.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,20 @@ public function getOpts(): array;
153153
public function getArgs(): array;
154154

155155
/**
156+
* Get args help data
157+
*
158+
* @return array
159+
* @psalm-return array<string, string>
160+
*/
161+
public function getArgsHelpData(): array;
162+
163+
/**
164+
* Get opts help data
165+
*
156166
* @return array
157167
* @psalm-return array<string, string>
158168
*/
159-
public function getOptSimpleDefines(): array;
169+
public function getOptsHelpData(): array;
160170

161171
/**
162172
* @return bool

src/Flags.php

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -856,19 +856,34 @@ public function getOpts(): array
856856
/**
857857
* @return array
858858
*/
859-
public function getOptSimpleDefines(): array
859+
public function getArgsHelpData(): array
860860
{
861-
$map = [];
862-
foreach ($this->options as $name => $define) {
863-
$names = $define['shorts'];
861+
$helpData = [];
862+
foreach ($this->arguments as $arg) {
863+
$name = $arg->getHelpName();
864+
// append
865+
$helpData[$name] = $arg->getDesc(true);
866+
}
867+
868+
return $helpData;
869+
}
870+
871+
/**
872+
* @return array
873+
*/
874+
public function getOptsHelpData(): array
875+
{
876+
$helpData = [];
877+
foreach ($this->options as $name => $opt) {
878+
$names = $opt['shorts'];
864879
$names[] = $name;
865880

866881
$helpName = FlagUtil::buildOptHelpName($names);
867-
868-
$map[$helpName] = $define['desc'];
882+
// append
883+
$helpData[$helpName] = $opt->getDesc(true);
869884
}
870885

871-
return $map;
886+
return $helpData;
872887
}
873888

874889
/**

src/FlagsParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ abstract class FlagsParser implements ParserInterface
6666
];
6767

6868
/**
69-
* TODO If locked, cannot add option and argument
69+
* If locked, cannot add option and argument
7070
*
7171
* @var bool
7272
*/

src/SFlags.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use function strpos;
2828
use function substr;
2929
use function trim;
30+
use function ucfirst;
3031

3132
/**
3233
* Class SFlags
@@ -889,19 +890,34 @@ public function getArgs(): array
889890
/**
890891
* @return array
891892
*/
892-
public function getOptSimpleDefines(): array
893+
public function getArgsHelpData(): array
893894
{
894-
$map = [];
895+
$helpData = [];
896+
foreach ($this->argDefines as $define) {
897+
$name = $define['name'];
898+
899+
$helpData[$name] = $define['desc'];
900+
}
901+
902+
return $helpData;
903+
}
904+
905+
/**
906+
* @return array
907+
*/
908+
public function getOptsHelpData(): array
909+
{
910+
$helpData = [];
895911
foreach ($this->optDefines as $name => $define) {
896912
$names = $define['shorts'];
897913
$names[] = $name;
898914

899915
$helpName = FlagUtil::buildOptHelpName($names);
900916

901-
$map[$helpName] = $define['desc'];
917+
$helpData[$helpName] = ucfirst($define['desc']);
902918
}
903919

904-
return $map;
920+
return $helpData;
905921
}
906922

907923
/**

0 commit comments

Comments
 (0)