@@ -51,25 +51,61 @@ public function getOptions() : array
5151
5252 protected function listCommands () : void
5353 {
54- $ width = 0 ;
55- $ lengths = [];
56- foreach (\array_keys ($ this ->console ->getCommands ()) as $ name ) {
57- $ lengths [$ name ] = \mb_strlen ($ name );
58- if ($ lengths [$ name ] > $ width ) {
59- $ width = $ lengths [$ name ];
54+ $ groupDefault = [];
55+ $ groups = [];
56+ foreach ($ this ->console ->getCommands () as $ name => $ command ) {
57+ $ group = $ command ->getGroup ();
58+ if ($ group === null ) {
59+ $ groupDefault [$ name ] = $ command ;
60+ continue ;
6061 }
62+ $ groups [$ group ][$ name ] = $ command ;
6163 }
6264 CLI ::write (
63- $ this ->console ->getLanguage ()->render ('cli ' , 'commands ' ) . ': ' ,
65+ $ this ->console ->getLanguage ()->render ('cli ' , 'availableCommands ' ) . ': ' ,
6466 ForegroundColor::yellow
6567 );
66- foreach ($ this ->console ->getCommands () as $ name => $ command ) {
68+ [$ width , $ lengths ] = $ this ->getWidthAndLengths ($ groupDefault );
69+ foreach ($ groupDefault as $ name => $ command ) {
6770 CLI ::write (
6871 ' ' . CLI ::style ($ name , ForegroundColor::green) . ' '
72+ // @phpstan-ignore-next-line
6973 . \str_repeat (' ' , $ width - $ lengths [$ name ])
7074 . $ command ->getDescription ()
7175 );
7276 }
77+ \ksort ($ groups );
78+ foreach ($ groups as $ groupName => $ commands ) {
79+ CLI ::newLine ();
80+ CLI ::write (' ' . $ groupName . ': ' , ForegroundColor::brightYellow);
81+ [$ width , $ lengths ] = $ this ->getWidthAndLengths ($ commands );
82+ foreach ($ commands as $ name => $ command ) {
83+ CLI ::write (
84+ ' ' . CLI ::style ($ name , ForegroundColor::green) . ' '
85+ // @phpstan-ignore-next-line
86+ . \str_repeat (' ' , $ width - $ lengths [$ name ])
87+ . $ command ->getDescription ()
88+ );
89+ }
90+ }
91+ }
92+
93+ /**
94+ * @param array<string,Command> $commands
95+ *
96+ * @return array<array<string,int>|int>
97+ */
98+ protected function getWidthAndLengths (array $ commands ) : array
99+ {
100+ $ width = 0 ;
101+ $ lengths = [];
102+ foreach (\array_keys ($ commands ) as $ name ) {
103+ $ lengths [$ name ] = \mb_strlen ($ name );
104+ if ($ lengths [$ name ] > $ width ) {
105+ $ width = $ lengths [$ name ];
106+ }
107+ }
108+ return [$ width , $ lengths ];
73109 }
74110
75111 protected function showHeader () : void
0 commit comments