File tree Expand file tree Collapse file tree 4 files changed +48
-2
lines changed Expand file tree Collapse file tree 4 files changed +48
-2
lines changed Original file line number Diff line number Diff line change 28
28
use function is_callable ;
29
29
use function is_object ;
30
30
use function ksort ;
31
+ use function ltrim ;
31
32
use function method_exists ;
32
33
use function sprintf ;
33
34
use function strlen ;
34
35
use function strpos ;
35
36
use function trim ;
37
+ use function vdump ;
36
38
37
39
/**
38
40
* class AbstractFlags
@@ -693,15 +695,16 @@ protected function parseRuleOptName(string $key): array
693
695
694
696
// only name.
695
697
if (strpos ($ key , ', ' ) === false ) {
696
- return [$ key , []];
698
+ $ name = ltrim ($ key , '- ' );
699
+ return [$ name , []];
697
700
}
698
701
699
702
$ name = '' ;
700
703
$ keys = Str::explode ($ key , ', ' );
701
704
702
705
// TIP: first is the option name. remaining is shorts.
703
706
$ shorts = [];
704
- foreach ($ keys as $ i => $ k ) {
707
+ foreach ($ keys as $ k ) {
705
708
// support like '--name, -n'
706
709
$ k = ltrim ($ k , '- ' );
707
710
Original file line number Diff line number Diff line change @@ -74,4 +74,10 @@ public function getOpts(): array;
74
74
* @return array
75
75
*/
76
76
public function getArgs (): array ;
77
+
78
+ /**
79
+ * @return array
80
+ * @psalm-return array<string, string>
81
+ */
82
+ public function getOptSimpleDefines (): array ;
77
83
}
Original file line number Diff line number Diff line change @@ -853,6 +853,24 @@ public function getOpts(): array
853
853
return $ opts ;
854
854
}
855
855
856
+ /**
857
+ * @return array
858
+ */
859
+ public function getOptSimpleDefines (): array
860
+ {
861
+ $ map = [];
862
+ foreach ($ this ->options as $ name => $ define ) {
863
+ $ names = $ define ['shorts ' ];
864
+ $ names [] = $ name ;
865
+
866
+ $ helpName = FlagUtil::buildOptHelpName ($ names );
867
+
868
+ $ map [$ helpName ] = $ define ['desc ' ];
869
+ }
870
+
871
+ return $ map ;
872
+ }
873
+
856
874
/**
857
875
* @param string $name
858
876
*
Original file line number Diff line number Diff line change 23
23
use function strpos ;
24
24
use function substr ;
25
25
use function trim ;
26
+ use function vdump ;
26
27
27
28
/**
28
29
* Class SFlags
@@ -761,6 +762,24 @@ public function getArgs(): array
761
762
* helper methods
762
763
***************************************************************/
763
764
765
+ /**
766
+ * @return array
767
+ */
768
+ public function getOptSimpleDefines (): array
769
+ {
770
+ $ map = [];
771
+ foreach ($ this ->optDefines as $ name => $ define ) {
772
+ $ names = $ define ['shorts ' ];
773
+ $ names [] = $ name ;
774
+
775
+ $ helpName = FlagUtil::buildOptHelpName ($ names );
776
+
777
+ $ map [$ helpName ] = $ define ['desc ' ];
778
+ }
779
+
780
+ return $ map ;
781
+ }
782
+
764
783
/**
765
784
* @param string|int $nameOrIndex
766
785
*
You can’t perform that action at this time.
0 commit comments