From d659fa2a8015f10bd387b25e8e23f9ba23c41018 Mon Sep 17 00:00:00 2001 From: ssw Date: Fri, 17 Jul 2026 11:49:25 +0800 Subject: [PATCH] feat(dacli): integrate enrichHelp into installHelpHook via installHelpHookWithPatterns --- src/core/help.ts | 14 ++++++++++++++ tests/core/help.spec.ts | 20 +++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/core/help.ts b/src/core/help.ts index cde10be..9d6deca 100644 --- a/src/core/help.ts +++ b/src/core/help.ts @@ -7,6 +7,7 @@ * - installHelpHook() (Task 1.3): 双路径注入 — .description(purpose) + .addHelpText('after', ...) */ import type { Command } from 'commander' +import { enrichHelp } from '../commands/_anti_patterns' export interface DacliHelp { purpose: string @@ -133,3 +134,16 @@ export function installHelpHook(command: Command, help: DacliHelp): void { command.addHelpText('after', `\n${rendered}`) } } + +/** + * 增强版 installHelpHook: 自动从 ANTI_PATTERNS 注入反模式. + * 在所有 migrate 完成的命令中使用, 以启用 Pitfalls / Best Practices / Decision Tree / Related Refs. + */ +export function installHelpHookWithPatterns( + command: Command, + fullCmd: string, + help: DacliHelp +): void { + const enriched = enrichHelp(fullCmd, help) + installHelpHook(command, enriched) +} diff --git a/tests/core/help.spec.ts b/tests/core/help.spec.ts index 152a071..9e07dec 100644 --- a/tests/core/help.spec.ts +++ b/tests/core/help.spec.ts @@ -1,5 +1,5 @@ import { describe, it, expect } from 'vitest' -import { renderDacliHelp, installHelpHook } from '../../src/core/help' +import { renderDacliHelp, installHelpHook, installHelpHookWithPatterns } from '../../src/core/help' import type { DacliHelp } from '../../src/core/help' import { Command } from 'commander' @@ -122,3 +122,21 @@ describe('installHelpHook', () => { expect(captured).toContain('use --autoRelease') }) }) + +describe('installHelpHookWithPatterns', () => { + it('should auto-inject ANTI_PATTERNS when command name matches', () => { + const cmd = new Command('form') + const sub = cmd.command('create') + installHelpHookWithPatterns(sub, 'form create', { purpose: 'Create form' }) + + let captured = '' + sub.configureOutput({ writeOut: (s) => { captured += s } }) + sub.outputHelp() + + // Pitfalls section auto-injected from ANTI_PATTERNS via enrichHelp + expect(captured).toContain('Pitfalls') + expect(captured).toContain('❌') + // The purpose should come from Commander .description() + expect(captured).toContain('Create form') + }) +})