66use Inhere \Console \Exception \FlagException ;
77use Inhere \Console \Flag \Traits \FlagArgumentsTrait ;
88use Inhere \Console \Flag \Traits \FlagOptionsTrait ;
9+ use Inhere \Console \Flag \Traits \FlagParsingTrait ;
10+ use Toolkit \Stdlib \Obj \AbstractObj ;
911use function array_shift ;
1012use function count ;
1113use function ltrim ;
1719 *
1820 * @package Inhere\Console\Flag
1921 */
20- class Flags
22+ class Flags extends AbstractObj
2123{
2224 use FlagArgumentsTrait;
2325 use FlagOptionsTrait;
26+ use FlagParsingTrait;
2427 use NameAliasTrait;
2528
2629 /**
@@ -33,38 +36,11 @@ class Flags
3336 */
3437 private $ helpRenderer ;
3538
36- /**
37- * @var bool
38- */
39- private $ parsed = false ;
40-
4139 /**
4240 * @var bool
4341 */
4442 private $ autoBindArgs = false ;
4543
46- /**
47- * The raw input args
48- *
49- * @var array
50- */
51- private $ rawArgs = [];
52-
53- /**
54- * The remaining args on parsed
55- *
56- * @var array
57- */
58- private $ args = [];
59-
60- /**
61- * @return $this
62- */
63- public static function new (): self
64- {
65- return new self ();
66- }
67-
6844 /**
6945 * @return $this
7046 */
@@ -143,7 +119,7 @@ public function parse(array $args = null): array
143119 * - found `-h|--help` flag
144120 * - found first arg(not an option)
145121 *
146- * @return array [bool, status]
122+ * @return array [goon: bool, status: int ]
147123 */
148124 protected function parseOne (): array
149125 {
@@ -166,6 +142,11 @@ protected function parseOne(): array
166142 return [false , self ::STATUS_OK ];
167143 }
168144
145+ // NOTICE: will stop parse option on found '--'
146+ if ($ arg === '-- ' ) {
147+ return [false , self ::STATUS_OK ];
148+ }
149+
169150 $ name = ltrim ($ arg , '- ' );
170151
171152 // invalid arg. eg: '--' // ignore
@@ -209,7 +190,7 @@ protected function parseOne(): array
209190 if (!$ hasVal && count ($ this ->args ) > 0 ) {
210191 // value is next arg
211192 $ hasVal = true ;
212- $ ntArg = $ this ->args [0 ];
193+ $ ntArg = $ this ->args [0 ];
213194
214195 // is not an option value.
215196 if ($ ntArg [0 ] === '- ' ) {
@@ -242,7 +223,7 @@ public function reset(bool $clearDefined = false): void
242223 }
243224
244225 // clear match results
245- $ this ->parsed = false ;
226+ $ this ->parsed = false ;
246227 $ this ->matched = [];
247228 $ this ->rawArgs = $ this ->args = [];
248229 }
@@ -316,22 +297,6 @@ public function setHelpRenderer(callable $helpRenderer): void
316297 $ this ->helpRenderer = $ helpRenderer ;
317298 }
318299
319- /**
320- * @return array
321- */
322- public function getRawArgs (): array
323- {
324- return $ this ->rawArgs ;
325- }
326-
327- /**
328- * @return array
329- */
330- public function getArgs (): array
331- {
332- return $ this ->args ;
333- }
334-
335300 /**
336301 * @return bool
337302 */
@@ -348,11 +313,4 @@ public function setAutoBindArgs(bool $autoBindArgs): void
348313 $ this ->autoBindArgs = $ autoBindArgs ;
349314 }
350315
351- /**
352- * @return bool
353- */
354- public function isParsed (): bool
355- {
356- return $ this ->parsed ;
357- }
358316}
0 commit comments