1010 *
1111 * @link https://github.com/adhocore/cli
1212 */
13- class Option
13+ class Option extends Parameter
1414{
15- use InflectsString;
16-
1715 protected $ short ;
1816
1917 protected $ long ;
2018
21- protected $ desc ;
22-
23- protected $ rawCmd ;
24-
25- protected $ default ;
26-
27- protected $ required = true ;
28-
29- protected $ optional = false ;
30-
31- protected $ variadic = false ;
32-
3319 protected $ filter ;
3420
35- public function __construct (string $ cmd , string $ desc = null , $ default = null , callable $ filter = null )
21+ public function __construct (string $ raw , string $ desc = null , $ default = null , callable $ filter = null )
3622 {
37- $ this ->rawCmd = $ cmd ;
38- $ this ->desc = $ desc ;
39- $ this ->default = $ default ;
40- $ this ->filter = $ filter ;
41- $ this ->required = \strpos ($ cmd , '< ' ) !== false ;
42- $ this ->optional = \strpos ($ cmd , '[ ' ) !== false ;
43-
44- if ($ this ->variadic = \strpos ($ cmd , '... ' ) !== false ) {
45- $ this ->default = (array ) $ this ->default ;
46- }
23+ $ this ->filter = $ filter ;
4724
48- $ this -> parse ( $ cmd );
25+ parent :: __construct ( $ raw , $ desc , $ default );
4926 }
5027
51- protected function parse (string $ cmd )
28+ protected function parse (string $ raw )
5229 {
53- if (\strpos ($ cmd , '-with- ' ) !== false ) {
30+ if (\strpos ($ raw , '-with- ' ) !== false ) {
5431 $ this ->default = false ;
55- } elseif (\strpos ($ cmd , '-no- ' ) !== false ) {
32+ } elseif (\strpos ($ raw , '-no- ' ) !== false ) {
5633 $ this ->default = true ;
5734 }
5835
59- $ parts = \preg_split ('/[\s,\|]+/ ' , $ cmd );
36+ $ parts = \preg_split ('/[\s,\|]+/ ' , $ raw );
6037
6138 $ this ->short = $ this ->long = $ parts [0 ];
6239 if (isset ($ parts [1 ])) {
6340 $ this ->long = $ parts [1 ];
6441 }
42+
43+ $ this ->name = \str_replace (['-- ' , 'no- ' , 'with- ' ], '' , $ this ->long );
6544 }
6645
6746 public function long (): string
@@ -74,41 +53,11 @@ public function short(): string
7453 return $ this ->short ;
7554 }
7655
77- public function name (): string
78- {
79- return \str_replace (['-- ' , 'no- ' , 'with- ' ], '' , $ this ->long );
80- }
81-
82- public function attributeName (): string
83- {
84- return $ this ->toCamelCase ($ this ->name ());
85- }
86-
8756 public function is ($ arg ): bool
8857 {
8958 return $ this ->short === $ arg || $ this ->long === $ arg ;
9059 }
9160
92- public function required (): bool
93- {
94- return $ this ->required ;
95- }
96-
97- public function optional (): bool
98- {
99- return $ this ->optional ;
100- }
101-
102- public function variadic (): bool
103- {
104- return $ this ->variadic ;
105- }
106-
107- public function default ()
108- {
109- return $ this ->default ;
110- }
111-
11261 public function bool (): bool
11362 {
11463 return \preg_match ('/\-no|\-with/ ' , $ this ->long ) > 0 ;
0 commit comments