1515use Override ;
1616
1717class ListSubcommands extends BuiltinSubcommandAbstract {
18- protected const string PADDING_BLOCK = ' ' ;
19-
2018 protected const string HEADER_DEFAULT = '-- ' ;
2119
2220
@@ -27,6 +25,10 @@ class ListSubcommands extends BuiltinSubcommandAbstract {
2725 protected readonly bool $ isSlim ;
2826 protected readonly string $ subcommandNamePart ;
2927
28+ protected readonly int $ paddingLeftMain ;
29+ protected readonly int $ paddingLeftCommand ;
30+ protected readonly int $ paddingLeftCommandDescription ;
31+
3032 #[Override]
3133 public static function getScriptInnerName (): string {
3234 return 'list ' ;
@@ -58,6 +60,10 @@ public function __construct(CliRequest $request) {
5860
5961 $ this ->isSlim = $ request ->getParamAsBool ('slim ' );
6062 $ this ->subcommandNamePart = $ request ->getParamAsString ('subcommand-name-part ' );
63+
64+ $ this ->paddingLeftMain = $ this ->isSlim ? 0 : max (0 , $ this ->environmentConfig ->listPaddingLeftMain );
65+ $ this ->paddingLeftCommand = max (0 , $ this ->environmentConfig ->listPaddingLeftCommand );
66+ $ this ->paddingLeftCommandDescription = max (0 , $ this ->environmentConfig ->listPaddingLeftCommandDescription );
6167 }
6268
6369 public function execute (): void {
@@ -89,7 +95,6 @@ public function execute(): void {
8995 $ subcommandGroupsAuto = [];
9096
9197 $ subcommandNameColumnWidthMax = 0 ;
92- $ padBlockWidth = mb_strlen (static ::PADDING_BLOCK );
9398 foreach ($ this ->parentConfig ->getBranches () as $ subcommandName => $ subcommandConfig ) {
9499 $ isBuiltInSubcommand = array_key_exists ($ subcommandName , $ builtInSubcommands );
95100
@@ -111,8 +116,8 @@ public function execute(): void {
111116 } else {
112117 $ nodeLevel = mb_substr_count ($ subcommandName , static ::NAME_SECTION_SEPARATOR );
113118 }
114- $ subcommandNameColumnWidth = $ padBlockWidth * max ( $ this -> isSlim ? 0 : 1 , $ nodeLevel )
115- + mb_strlen ( $ subcommandName );
119+ $ subcommandNameColumnWidth = mb_strlen ( $ subcommandName )
120+ + $ this -> paddingLeftCommand * max ( $ this -> isSlim ? 0 : 1 , $ nodeLevel );
116121 if ($ subcommandNameColumnWidthMax < $ subcommandNameColumnWidth ) {
117122 $ subcommandNameColumnWidthMax = $ subcommandNameColumnWidth ;
118123 }
@@ -223,7 +228,8 @@ protected function outputNode(
223228 echo PHP_EOL ;
224229 }
225230
226- $ subcommandNameOutput = str_repeat (static ::PADDING_BLOCK , $ nodeLevel ) . $ elementName ;
231+ $ subcommandNameOutput = str_repeat (' ' , $ this ->paddingLeftMain + $ this ->paddingLeftCommand * $ nodeLevel )
232+ . $ elementName ;
227233 if ($ elementValue instanceof Config) {
228234 $ subcommandNameOutputFormatted = $ subcommandNameOutput ;
229235 if ('' !== $ this ->subcommandNamePart ) {
@@ -235,18 +241,19 @@ protected function outputNode(
235241 }
236242 echo $ this ->formatter ->paramValue ($ subcommandNameOutputFormatted );
237243 } else {
238- if (0 === $ nodeLevel ) {
239- echo ' ' ;
240- }
241244 echo $ this ->formatter ->helpNote ($ subcommandNameOutput );
242245 }
243246
244247 if ($ elementValue instanceof Config) {
245248 $ shortDescription = HelpGenerator::getScriptShortDescription ($ elementValue , $ this ->environmentConfig );
246249
247250 if ('' !== $ shortDescription ) {
248- echo mb_str_pad ('' , $ subcommandNameColumnWidthMax - mb_strlen ($ subcommandNameOutput ))
249- . static ::PADDING_BLOCK . $ shortDescription ;
251+ echo str_repeat (
252+ ' ' ,
253+ $ this ->paddingLeftMain + $ this ->paddingLeftCommandDescription
254+ + $ subcommandNameColumnWidthMax - mb_strlen ($ subcommandNameOutput ),
255+ )
256+ . $ shortDescription ;
250257 }
251258 }
252259 echo PHP_EOL ;
0 commit comments