#!/usr/bin/env node /** * cli.ts — dacli TS 版入口 * * 调用: `npx tsx src/cli.ts ` 或 `node --import tsx src/cli.ts ` * * 设计: 嵌套子命令 (form/menu/dm/dict/workflow/doc/apis 父命令 + 子命令) * AI 友好: 每个命令支持 --ai-help / --example / --source */ import { Command } from 'commander' import { buildLoginCommand } from './commands/login.ts' import { buildStatusCommand } from './commands/status.ts' import { buildSwitchAppCommand } from './commands/switch-app.ts' import { buildFormCommand } from './commands/form/index.ts' import { buildDmCommand } from './commands/dm/index.ts' import { buildDictCommand } from './commands/dict/index.ts' import { buildMenuCommand } from './commands/menu/index.ts' import { buildDiCommand } from './commands/di/index.ts' import { buildWorkflowCommand } from './commands/workflow/index.ts' import { buildDocCommand } from './commands/doc/index.ts' import { buildApisCommand } from './commands/apis/index.ts' import { buildDatasourceCommand } from './commands/datasource/index.ts' import { buildReportCommand } from './commands/report/index.ts' import { buildPortalCommand } from './commands/portal/index.ts' import { buildBigscreenCommand } from './commands/bigscreen/index.ts' import { maybeInterceptAiHelp } from './core/help.ts' import { log } from './core/log.ts' import { DacliError } from './core/types.ts' const VERSION = '0.1.0' const program = new Command() .name('dacli') .description('dacli (TS 版) — AI 驱动的 JNPF CLI. 0 差错 baseline 复刻.') .version(VERSION) .showHelpAfterError(true) // ----- 顶层命令 ----- program.addCommand(buildLoginCommand()) program.addCommand(buildStatusCommand()) program.addCommand(buildSwitchAppCommand()) // ----- 嵌套父命令 ----- program.addCommand(buildFormCommand()) program.addCommand(buildDmCommand()) program.addCommand(buildDictCommand()) program.addCommand(buildMenuCommand()) program.addCommand(buildDiCommand()) program.addCommand(buildWorkflowCommand()) program.addCommand(buildDocCommand()) program.addCommand(buildApisCommand()) // v0.8 W7-D3 新增 4 父命令 program.addCommand(buildDatasourceCommand()) program.addCommand(buildReportCommand()) program.addCommand(buildPortalCommand()) program.addCommand(buildBigscreenCommand()) // ----- main ----- // AI flag 拦截 (在 parse 之前, 避免 requiredOption 校验失败) if (maybeInterceptAiHelp(program)) { // 已 exit } program.parseAsync(process.argv).catch((err: unknown) => { if (err instanceof DacliError) { log.error(`${err.message}`) if (err.raw && process.env.DACLI_DEBUG === '1') log.dim(err.raw) process.exit(1) } log.error(`${(err as Error).message}`) if (process.env.DACLI_DEBUG === '1') console.error(err) process.exit(1) })