@@ -25,6 +25,13 @@ interface CommandNode {
2525 children : Map < string , CommandNode > ;
2626}
2727
28+ const AUTH_LABELS = {
29+ apiKey : "API Key" ,
30+ console : "Console" ,
31+ openapi : "AK/SK" ,
32+ none : "No Auth" ,
33+ } satisfies Record < AuthRequirement , string > ;
34+
2835/**
2936 * What a command path resolves to in the registry. The single judgement that
3037 * feeds `resolve()` — no scattered `isGroupPath` + throwing `resolve`.
@@ -157,14 +164,37 @@ export class CommandRegistry {
157164 } ;
158165 }
159166
160- private buildResourceLines ( a : ( s : string ) => string , d : ( s : string ) => string ) : string {
161- const entries : Array < { path : string ; desc : string } > = [ ] ;
167+ private buildCommandLines (
168+ entries : Array < { path : string ; auth : AuthRequirement ; desc : string } > ,
169+ accent : ( text : string ) => string ,
170+ dim : ( text : string ) => string ,
171+ ) : string {
172+ const maxPathLength = Math . max ( ...entries . map ( ( entry ) => entry . path . length ) ) ;
173+ const maxAuthLength = Math . max (
174+ ...entries . map ( ( entry ) => `[${ AUTH_LABELS [ entry . auth ] } ]` . length ) ,
175+ ) ;
176+ const rows = entries . map ( ( entry ) => {
177+ const authLabel = `[${ AUTH_LABELS [ entry . auth ] } ]` ;
178+ return ` ${ accent ( entry . path . padEnd ( maxPathLength + 2 ) ) } ${ accent ( authLabel . padEnd ( maxAuthLength + 2 ) ) } ${ dim ( entry . desc ) } ` ;
179+ } ) ;
180+ return rows . join ( "\n" ) ;
181+ }
182+
183+ private buildResourceLines (
184+ accent : ( text : string ) => string ,
185+ dim : ( text : string ) => string ,
186+ ) : string {
187+ const entries : Array < { path : string ; auth : AuthRequirement ; desc : string } > = [ ] ;
162188
163189 const collect = ( node : CommandNode , prefix : string ) => {
164190 for ( const [ name , child ] of node . children ) {
165191 const fullPath = prefix ? `${ prefix } ${ name } ` : name ;
166192 if ( child . command ) {
167- entries . push ( { path : fullPath , desc : child . command . description } ) ;
193+ entries . push ( {
194+ path : fullPath ,
195+ auth : child . command . auth ,
196+ desc : child . command . description ,
197+ } ) ;
168198 }
169199 if ( child . children . size > 0 ) {
170200 collect ( child , fullPath ) ;
@@ -173,8 +203,7 @@ export class CommandRegistry {
173203 } ;
174204 collect ( this . root , "" ) ;
175205
176- const maxLen = Math . max ( ...entries . map ( ( e ) => e . path . length ) ) ;
177- return entries . map ( ( e ) => ` ${ a ( e . path . padEnd ( maxLen + 2 ) ) } ${ d ( e . desc ) } ` ) . join ( "\n" ) ;
206+ return this . buildCommandLines ( entries , accent , dim ) ;
178207 }
179208
180209 private buildFlagLines (
@@ -341,6 +370,7 @@ ${authFlagSections ? `${authFlagSections}\n\n` : ""}${b("Getting Help:")}
341370
342371 out . write ( `\n${ cmd . description } \n` ) ;
343372 out . write ( `${ b ( "Usage:" ) } ${ prefix } ${ cmd . usageArgs ? ` ${ cmd . usageArgs } ` : "" } \n` ) ;
373+ out . write ( `${ b ( "Authentication:" ) } ${ a ( AUTH_LABELS [ cmd . auth ] ) } \n` ) ;
344374 const flagEntries = [
345375 ...Object . entries ( cmd . flags ?? { } ) ,
346376 ...Object . entries ( credentialFlagDefs ( cmd ) ) ,
@@ -373,18 +403,25 @@ ${authFlagSections ? `${authFlagSections}\n\n` : ""}${b("Getting Help:")}
373403 }
374404
375405 private printChildren ( node : CommandNode , prefix : string , out : NodeJS . WriteStream ) : void {
376- const entries : Array < { fullName : string ; description : string } > = [ ] ;
377- const collect = ( n : CommandNode , p : string ) => {
378- for ( const [ name , child ] of n . children ) {
406+ const entries : Array < { path : string ; auth : AuthRequirement ; desc : string } > = [ ] ;
407+ const collect = ( currentNode : CommandNode , currentPath : string ) => {
408+ for ( const [ name , child ] of currentNode . children ) {
379409 if ( child . command )
380- entries . push ( { fullName : `${ p } ${ name } ` , description : child . command . description } ) ;
381- if ( child . children . size > 0 ) collect ( child , `${ p } ${ name } ` ) ;
410+ entries . push ( {
411+ path : `${ currentPath } ${ name } ` ,
412+ auth : child . command . auth ,
413+ desc : child . command . description ,
414+ } ) ;
415+ if ( child . children . size > 0 ) collect ( child , `${ currentPath } ${ name } ` ) ;
382416 }
383417 } ;
384418 collect ( node , prefix ) ;
385- const maxLen = Math . max ( ...entries . map ( ( e ) => e . fullName . length ) ) ;
386- for ( const { fullName, description } of entries ) {
387- out . write ( ` ${ this . accent ( fullName . padEnd ( maxLen ) , out ) } ${ this . dim ( description , out ) } \n` ) ;
388- }
419+ out . write (
420+ this . buildCommandLines (
421+ entries ,
422+ ( text ) => this . accent ( text , out ) ,
423+ ( text ) => this . dim ( text , out ) ,
424+ ) + "\n" ,
425+ ) ;
389426 }
390427}
0 commit comments