feat(dacli): integrate enrichHelp into installHelpHook via installHelpHookWithPatterns
This commit is contained in:
1 parent
394b8ce867
commit
d659fa2a80
2 files changed
+33
-1
No files matched your search
@@ -7,6 +7,7 @@
|
|||||||
* - installHelpHook() (Task 1.3): 双路径注入 — .description(purpose) + .addHelpText('after', ...)
|
* - installHelpHook() (Task 1.3): 双路径注入 — .description(purpose) + .addHelpText('after', ...)
|
||||||
*/
|
*/
|
||||||
import type { Command } from 'commander'
|
import type { Command } from 'commander'
|
||||||
|
import { enrichHelp } from '../commands/_anti_patterns'
|
||||||
|
|
||||||
export interface DacliHelp {
|
export interface DacliHelp {
|
||||||
purpose: string
|
purpose: string
|
||||||
@@ -133,3 +134,16 @@ export function installHelpHook(command: Command, help: DacliHelp): void {
|
|||||||
command.addHelpText('after', `\n${rendered}`)
|
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)
|
||||||
|
}
|
||||||
+19
-1
@@ -1,5 +1,5 @@
|
|||||||
import { describe, it, expect } from 'vitest'
|
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 type { DacliHelp } from '../../src/core/help'
|
||||||
import { Command } from 'commander'
|
import { Command } from 'commander'
|
||||||
|
|
||||||
@@ -122,3 +122,21 @@ describe('installHelpHook', () => {
|
|||||||
expect(captured).toContain('use --autoRelease')
|
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')
|
||||||
|
})
|
||||||
|
})
|
||||||
Reference in new issue
Block a user