@@ -25,10 +25,11 @@ class Application extends AbstractApplication
2525 * Register a app group command(by controller)
2626 * @param string $name The controller name
2727 * @param string $class The controller class
28+ * @param null|array|string $option
2829 * @return static
2930 * @throws \InvalidArgumentException
3031 */
31- public function controller (string $ name , string $ class = null )
32+ public function controller (string $ name , string $ class = null , $ option = null )
3233 {
3334 if (!$ class && class_exists ($ name )) {
3435 /** @var Controller $class */
@@ -54,6 +55,18 @@ public function controller(string $name, string $class = null)
5455
5556 $ this ->controllers [$ name ] = $ class ;
5657
58+ if (!$ option ) {
59+ return $ this ;
60+ }
61+
62+ // have option information
63+ if (\is_string ($ option )) {
64+ $ this ->addCommandMessage ($ name , $ option );
65+ } elseif (\is_array ($ option )) {
66+ $ this ->addCommandAliases ($ name , $ option ['aliases ' ] ?? null );
67+ $ this ->addCommandMessage ($ name , $ option ['description ' ] ?? null );
68+ }
69+
5770 return $ this ;
5871 }
5972
@@ -79,11 +92,11 @@ public function controllers(array $controllers)
7992 * Register a app independent console command
8093 * @param string|Command $name
8194 * @param string|\Closure|Command $handler
82- * @param null|string $description
95+ * @param null|array| string $option
8396 * @return $this
8497 * @throws \InvalidArgumentException
8598 */
86- public function command (string $ name , $ handler = null , $ description = null )
99+ public function command (string $ name , $ handler = null , $ option = null )
87100 {
88101 if (!$ handler && class_exists ($ name )) {
89102 /** @var Command $name */
@@ -119,8 +132,16 @@ public function command(string $name, $handler = null, $description = null)
119132 // is an class name string
120133 $ this ->commands [$ name ] = $ handler ;
121134
122- if ($ description ) {
123- $ this ->addCommandMessage ($ name , $ description );
135+ if (!$ option ) {
136+ return $ this ;
137+ }
138+
139+ // have option information
140+ if (\is_string ($ option )) {
141+ $ this ->addCommandMessage ($ name , $ option );
142+ } elseif (\is_array ($ option )) {
143+ $ this ->addCommandAliases ($ name , $ option ['aliases ' ] ?? null );
144+ $ this ->addCommandMessage ($ name , $ option ['description ' ] ?? null );
124145 }
125146
126147 return $ this ;
@@ -231,26 +252,30 @@ protected function getFileFilter()
231252 */
232253 protected function dispatch ($ name )
233254 {
234- $ sep = $ this ->delimiter ?: '/ ' ;
255+ $ sep = $ this ->delimiter ?: ': ' ;
235256
236257 //// is a command name
237258
238- if ($ this ->isCommand ($ name )) {
239- return $ this ->runCommand ($ name , true );
259+ $ realName = $ this ->getRealCommandName ($ name );
260+
261+ if ($ this ->isCommand ($ realName )) {
262+ return $ this ->runCommand ($ realName , true );
240263 }
241264
242265 //// is a controller name
243266
244267 $ action = '' ;
245268
246- // like 'home/ index'
269+ // like 'home: index'
247270 if (strpos ($ name , $ sep ) > 0 ) {
248271 $ input = array_filter (explode ($ sep , $ name ));
249272 list ($ name , $ action ) = \count ($ input ) > 2 ? array_splice ($ input , 2 ) : $ input ;
250273 }
251274
252- if ($ this ->isController ($ name )) {
253- return $ this ->runAction ($ name , $ action , true );
275+ $ realName = $ this ->getRealCommandName ($ name );
276+
277+ if ($ this ->isController ($ realName )) {
278+ return $ this ->runAction ($ realName , $ action , true );
254279 }
255280
256281 // command not found
0 commit comments