@@ -88,7 +88,7 @@ public function __construct($argv = null)
8888 list ($ this ->args , $ this ->sOpts , $ this ->lOpts ) = OptArgParse::byArgv ($ argv );
8989
9090 // collect command `server`
91- $ this ->command = isset ($ this ->args [0 ]) ? array_shift ($ this ->args ) : '' ;
91+ $ this ->command = isset ($ this ->args [0 ]) ? array_shift ($ this ->args ) : null ;
9292 }
9393
9494 /**
@@ -124,9 +124,34 @@ public function read($question = null, $nl = false): string
124124 return trim (fgets ($ this ->inputStream ));
125125 }
126126
127- /////////////////////////////////////////////////////////////////////////////////////////
128- /// arguments (eg: name=john city=chengdu)
129- /////////////////////////////////////////////////////////////////////////////////////////
127+ /////////////////////////////////////////////////////////////////////////////////////////
128+ /// arguments (eg: name=john city=chengdu)
129+ /////////////////////////////////////////////////////////////////////////////////////////
130+
131+ /**
132+ * @return array
133+ */
134+ public function getArguments (): array
135+ {
136+ return $ this ->args ;
137+ }
138+
139+ /**
140+ * @return array
141+ */
142+ public function getArgs (): array
143+ {
144+ return $ this ->args ;
145+ }
146+
147+ /**
148+ * @param array $args
149+ * @param bool $replace
150+ */
151+ public function setArgs (array $ args , $ replace = false )
152+ {
153+ $ this ->args = $ replace ? $ args : array_merge ($ this ->args , $ args );
154+ }
130155
131156 /**
132157 * @param string|int $name
@@ -243,9 +268,9 @@ public function sameArg(array $names, $default = null)
243268 return $ default ;
244269 }
245270
246- /////////////////////////////////////////////////////////////////////////////////////////
247- /// long/short options (eg: -d --help)
248- /////////////////////////////////////////////////////////////////////////////////////////
271+ /////////////////////////////////////////////////////////////////////////////////////////
272+ /// long/short options (eg: -d --help)
273+ /////////////////////////////////////////////////////////////////////////////////////////
249274
250275 /**
251276 * get (long/short)opt value
@@ -382,6 +407,31 @@ public function sBoolOpt(string $name, $default = false): bool
382407 return is_bool ($ val ) ? $ val : (bool )$ default ;
383408 }
384409
410+ /**
411+ * @return array
412+ */
413+ public function getShortOpts (): array
414+ {
415+ return $ this ->sOpts ;
416+ }
417+
418+ /**
419+ * @return array
420+ */
421+ public function getSOpts (): array
422+ {
423+ return $ this ->sOpts ;
424+ }
425+
426+ /**
427+ * @param array $sOpts
428+ * @param bool $replace
429+ */
430+ public function setSOpts (array $ sOpts , $ replace = false )
431+ {
432+ $ this ->sOpts = $ replace ? $ sOpts : array_merge ($ this ->sOpts , $ sOpts );
433+ }
434+
385435 /////////////////// long-opts /////////////////////
386436
387437 /**
@@ -422,6 +472,31 @@ public function lBoolOpt(string $name, $default = false): bool
422472 return is_bool ($ val ) ? $ val : (bool )$ default ;
423473 }
424474
475+ /**
476+ * @return array
477+ */
478+ public function getLongOpts (): array
479+ {
480+ return $ this ->lOpts ;
481+ }
482+
483+ /**
484+ * @return array
485+ */
486+ public function getLOpts (): array
487+ {
488+ return $ this ->lOpts ;
489+ }
490+
491+ /**
492+ * @param array $lOpts
493+ * @param bool $replace
494+ */
495+ public function setLOpts (array $ lOpts , $ replace = false )
496+ {
497+ $ this ->lOpts = $ replace ? $ lOpts : array_merge ($ this ->lOpts , $ lOpts );
498+ }
499+
425500 /**
426501 * @return array
427502 */
@@ -430,9 +505,9 @@ public function getOpts(): array
430505 return array_merge ($ this ->sOpts , $ this ->lOpts );
431506 }
432507
433- /////////////////////////////////////////////////////////////////////////////////////////
434- /// getter/setter
435- /////////////////////////////////////////////////////////////////////////////////////////
508+ /////////////////////////////////////////////////////////////////////////////////////////
509+ /// getter/setter
510+ /////////////////////////////////////////////////////////////////////////////////////////
436511
437512 /**
438513 * @return string
@@ -467,11 +542,12 @@ public function setScript(string $script)
467542 }
468543
469544 /**
545+ * @param null|string $default
470546 * @return string
471547 */
472- public function getCommand (): string
548+ public function getCommand ($ default = null ): string
473549 {
474- return $ this ->command ;
550+ return $ this ->command ?: $ default ;
475551 }
476552
477553 /**
@@ -482,81 +558,6 @@ public function setCommand(string $command)
482558 $ this ->command = $ command ;
483559 }
484560
485- /**
486- * @return array
487- */
488- public function getArguments (): array
489- {
490- return $ this ->args ;
491- }
492-
493- /**
494- * @return array
495- */
496- public function getArgs (): array
497- {
498- return $ this ->args ;
499- }
500-
501- /**
502- * @param array $args
503- * @param bool $replace
504- */
505- public function setArgs (array $ args , $ replace = false )
506- {
507- $ this ->args = $ replace ? $ args : array_merge ($ this ->args , $ args );
508- }
509-
510- /**
511- * @return array
512- */
513- public function getShortOpts (): array
514- {
515- return $ this ->sOpts ;
516- }
517-
518- /**
519- * @return array
520- */
521- public function getSOpts (): array
522- {
523- return $ this ->sOpts ;
524- }
525-
526- /**
527- * @param array $sOpts
528- * @param bool $replace
529- */
530- public function setSOpts (array $ sOpts , $ replace = false )
531- {
532- $ this ->sOpts = $ replace ? $ sOpts : array_merge ($ this ->sOpts , $ sOpts );
533- }
534-
535- /**
536- * @return array
537- */
538- public function getLongOpts (): array
539- {
540- return $ this ->lOpts ;
541- }
542-
543- /**
544- * @return array
545- */
546- public function getLOpts (): array
547- {
548- return $ this ->lOpts ;
549- }
550-
551- /**
552- * @param array $lOpts
553- * @param bool $replace
554- */
555- public function setLOpts (array $ lOpts , $ replace = false )
556- {
557- $ this ->lOpts = $ replace ? $ lOpts : array_merge ($ this ->lOpts , $ lOpts );
558- }
559-
560561 /**
561562 * @return resource
562563 */
0 commit comments