Skip to content

MinLeeV5/devkeel / .harness/skills/new-subcommand

new-subcommand

Verified

为 DevKeel CLI 新增子命令的标准开发流程

子命令实现

何时使用

为 DevKeel CLI 新增一个子命令时(如 harness <new-cmd>)。

流程

Step 1: 注册命令

在 src/index.ts 中添加:

import { runNewCmd } from './commands/new-cmd.js'

program
  .command('new-cmd')
  .description('中文功能描述')
  .option('--flag', '选项说明')
  .action((opts) => runNewCmd(opts))

Step 2: 实现命令层

创建 src/commands/new-cmd.ts:

import * as p from '@clack/prompts'
import { someLogic } from '../lib/new-cmd.js'

export async function runNewCmd(opts?: { flag?: boolean }): Promise<void> {
  p.intro('harness new-cmd')
  // 交互 + 调用 lib
  p.outro('完成')
}

命令层只做:读参数 → 交互 → 调用 lib → 输出结果。

Step 3: 实现逻辑层

创建 src/lib/new-cmd.ts:

  • 纯函数,不引入 @clack/prompts
  • 文件操作前 fs.existsSync 守卫
  • 返回 plain object 或 null,不 throw

Step 4: 编写测试

创建 tests/new-cmd.test.ts:

  • 临时目录隔离(fs.mkdtempSync)
  • 真实文件系统验证
  • 覆盖正常路径 + 缺失输入 + 幂等性

Step 5: 验证

pnpm lint && pnpm test && pnpm build
node bin/devkeel.js new-cmd --help

Checklist

  • src/index.ts 注册命令
  • src/commands/new-cmd.ts 交互层
  • src/lib/new-cmd.ts 逻辑层(如有复杂逻辑)
  • tests/new-cmd.test.ts 测试
  • pnpm lint + pnpm test 通过
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 198kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 196kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 196kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 196kUpdated Claude CodeCodexVerifiedInstall