@@ -3,19 +3,36 @@ import type { Command } from "commander";
33import { formatDocsLink } from "../../packages/terminal-core/src/links.js" ;
44import { theme } from "../../packages/terminal-core/src/theme.js" ;
55import { defaultRuntime } from "../runtime.js" ;
6- import { registerAudioCapabilityCommands } from "./capability-cli/audio.js" ;
7- import { registerEmbeddingCapabilityCommands } from "./capability-cli/embedding.js" ;
8- import { registerImageCapabilityCommands } from "./capability-cli/image.js" ;
6+ import { resolveCliArgvInvocation } from "./argv-invocation.js" ;
97import { CAPABILITY_METADATA , findCapabilityMetadata } from "./capability-cli/metadata.js" ;
10- import { registerModelCapabilityCommands } from "./capability-cli/model.js" ;
118import { emitJsonOrText , providerSummaryText } from "./capability-cli/shared.js" ;
12- import { registerTtsCapabilityCommands } from "./capability-cli/tts.js" ;
13- import { registerVideoCapabilityCommands } from "./capability-cli/video.js" ;
14- import { registerWebCapabilityCommands } from "./capability-cli/web.js" ;
159import { runCommandWithRuntime } from "./cli-utils.js" ;
1610import { removeCommandByName } from "./program/command-tree.js" ;
1711
18- export { CAPABILITY_METADATA } from "./capability-cli/metadata.js" ;
12+ const capabilityCommandGroups = [
13+ [
14+ "model" ,
15+ async ( ) => ( await import ( "./capability-cli/model.js" ) ) . registerModelCapabilityCommands ,
16+ ] ,
17+ [
18+ "image" ,
19+ async ( ) => ( await import ( "./capability-cli/image.js" ) ) . registerImageCapabilityCommands ,
20+ ] ,
21+ [
22+ "audio" ,
23+ async ( ) => ( await import ( "./capability-cli/audio.js" ) ) . registerAudioCapabilityCommands ,
24+ ] ,
25+ [ "tts" , async ( ) => ( await import ( "./capability-cli/tts.js" ) ) . registerTtsCapabilityCommands ] ,
26+ [
27+ "video" ,
28+ async ( ) => ( await import ( "./capability-cli/video.js" ) ) . registerVideoCapabilityCommands ,
29+ ] ,
30+ [ "web" , async ( ) => ( await import ( "./capability-cli/web.js" ) ) . registerWebCapabilityCommands ] ,
31+ [
32+ "embedding" ,
33+ async ( ) => ( await import ( "./capability-cli/embedding.js" ) ) . registerEmbeddingCapabilityCommands ,
34+ ] ,
35+ ] as const ;
1936
2037function registerCapabilityListAndInspect ( capability : Command ) : void {
2138 capability
@@ -51,7 +68,34 @@ function registerCapabilityListAndInspect(capability: Command): void {
5168 } ) ;
5269}
5370
54- export function registerCapabilityCli ( program : Command ) : void {
71+ async function registerCapabilityDomainCommands (
72+ capability : Command ,
73+ argv : string [ ] ,
74+ ) : Promise < void > {
75+ const invocation = resolveCliArgvInvocation ( argv ) ;
76+ if ( ! invocation . hasHelpOrVersion ) {
77+ const selectedName = invocation . commandPath [ 1 ] ;
78+ if ( selectedName === "list" || selectedName === "inspect" ) {
79+ return ;
80+ }
81+ const selected = capabilityCommandGroups . find ( ( [ name ] ) => name === selectedName ) ;
82+ if ( selected ) {
83+ const register = await selected [ 1 ] ( ) ;
84+ register ( capability ) ;
85+ return ;
86+ }
87+ }
88+
89+ const registrars = await Promise . all ( capabilityCommandGroups . map ( ( [ , load ] ) => load ( ) ) ) ;
90+ for ( const register of registrars ) {
91+ register ( capability ) ;
92+ }
93+ }
94+
95+ export async function registerCapabilityCli (
96+ program : Command ,
97+ argv : string [ ] = process . argv ,
98+ ) : Promise < void > {
5599 removeCommandByName ( program , "infer" ) ;
56100 removeCommandByName ( program , "capability" ) ;
57101
@@ -66,11 +110,5 @@ export function registerCapabilityCli(program: Command): void {
66110 ) ;
67111
68112 registerCapabilityListAndInspect ( capability ) ;
69- registerModelCapabilityCommands ( capability ) ;
70- registerImageCapabilityCommands ( capability ) ;
71- registerAudioCapabilityCommands ( capability ) ;
72- registerTtsCapabilityCommands ( capability ) ;
73- registerVideoCapabilityCommands ( capability ) ;
74- registerWebCapabilityCommands ( capability ) ;
75- registerEmbeddingCapabilityCommands ( capability ) ;
113+ await registerCapabilityDomainCommands ( capability , argv ) ;
76114}
0 commit comments