1- import type { AnyCommand , FlagDef } from "bailian-cli-core" ;
1+ import type { AnyCommand , AuthRequirement , FlagDef , FlagsDef } from "bailian-cli-core" ;
22import { UsageError } from "bailian-cli-core" ;
33import {
44 CONSOLE_AUTH_FLAGS ,
@@ -42,6 +42,7 @@ export class CommandRegistry {
4242 private root : CommandNode = { children : new Map ( ) } ;
4343 /** Binary name shown in usage/help/error strings (e.g. "bl", "rag"). */
4444 private readonly cliName : string ;
45+ private readonly authRequirements = new Set < AuthRequirement > ( ) ;
4546
4647 constructor ( commands : Record < string , AnyCommand > , cliName : string ) {
4748 this . cliName = cliName ;
@@ -67,6 +68,7 @@ export class CommandRegistry {
6768 node = node . children . get ( part ) ! ;
6869 }
6970 node . command = command ;
71+ this . authRequirements . add ( command . auth ) ;
7072 }
7173
7274 getAllCommands ( ) : AnyCommand [ ] {
@@ -176,7 +178,7 @@ export class CommandRegistry {
176178 }
177179
178180 private buildFlagLines (
179- defs : Record < string , FlagDef > ,
181+ defs : FlagsDef ,
180182 a : ( s : string ) => string ,
181183 d : ( s : string ) => string ,
182184 ) : string {
@@ -188,6 +190,19 @@ export class CommandRegistry {
188190 return lines . map ( ( l ) => ` ${ a ( l . flag . padEnd ( maxLen + 2 ) ) } ${ d ( l . desc ) } ` ) . join ( "\n" ) ;
189191 }
190192
193+ private buildAuthFlagSection (
194+ auth : AuthRequirement ,
195+ label : string ,
196+ scope : string ,
197+ defs : FlagsDef ,
198+ b : ( s : string ) => string ,
199+ a : ( s : string ) => string ,
200+ d : ( s : string ) => string ,
201+ ) : string | null {
202+ if ( ! this . authRequirements . has ( auth ) ) return null ;
203+ return `${ b ( label ) } ${ d ( scope ) } \n${ this . buildFlagLines ( defs , a , d ) } ` ;
204+ }
205+
191206 // Color helpers — no-ops when output is not a TTY.
192207 private bold = ( s : string , out : NodeJS . WriteStream ) => ansi ( out ) . bold ( s ) ;
193208 private accent = ( s : string , out : NodeJS . WriteStream ) => ansi ( out ) . accent ( s ) ;
@@ -268,9 +283,37 @@ ${d(` ${this.cliName} pipeline run workflow.yaml --dry-run --output json`)}
268283
269284 const commandLines = this . buildResourceLines ( a , d ) ;
270285 const globalFlagLines = this . buildFlagLines ( GLOBAL_FLAGS , a , d ) ;
271- const modelFlagLines = this . buildFlagLines ( MODEL_AUTH_FLAGS , a , d ) ;
272- const consoleFlagLines = this . buildFlagLines ( CONSOLE_AUTH_FLAGS , a , d ) ;
273- const openapiFlagLines = this . buildFlagLines ( OPENAPI_AUTH_FLAGS , a , d ) ;
286+ const authFlagSections = [
287+ this . buildAuthFlagSection (
288+ "apiKey" ,
289+ "Model Auth Flags:" ,
290+ "(model-domain commands)" ,
291+ MODEL_AUTH_FLAGS ,
292+ b ,
293+ a ,
294+ d ,
295+ ) ,
296+ this . buildAuthFlagSection (
297+ "console" ,
298+ "Console Auth Flags:" ,
299+ "(console-domain commands)" ,
300+ CONSOLE_AUTH_FLAGS ,
301+ b ,
302+ a ,
303+ d ,
304+ ) ,
305+ this . buildAuthFlagSection (
306+ "openapi" ,
307+ "OpenAPI Auth Flags:" ,
308+ "(openapi-domain commands)" ,
309+ OPENAPI_AUTH_FLAGS ,
310+ b ,
311+ a ,
312+ d ,
313+ ) ,
314+ ]
315+ . filter ( ( section ) : section is string => section !== null )
316+ . join ( "\n\n" ) ;
274317
275318 out . write ( `
276319${ b ( "Usage:" ) } ${ this . cliName } <resource> <command> [flags]
@@ -281,16 +324,7 @@ ${commandLines}
281324${ b ( "Global Flags:" ) }
282325${ globalFlagLines }
283326
284- ${ b ( "Model Auth Flags:" ) } ${ d ( "(model-domain commands)" ) }
285- ${ modelFlagLines }
286-
287- ${ b ( "Console Auth Flags:" ) } ${ d ( "(console-domain commands)" ) }
288- ${ consoleFlagLines }
289-
290- ${ b ( "OpenAPI Auth Flags:" ) } ${ d ( "(openapi-domain commands)" ) }
291- ${ openapiFlagLines }
292-
293- ${ b ( "Getting Help:" ) }
327+ ${ authFlagSections ? `${ authFlagSections } \n\n` : "" } ${ b ( "Getting Help:" ) }
294328 ${ d ( "Add --help after any command to see its full list of flags, defaults," ) }
295329 ${ d ( "and usage examples. For example:" ) } ${ this . cliName } ${ this . helpExample ( ) } --help
296330` ) ;
0 commit comments