add-oclif-command
Add a new OCLIF command to a CLI package with proper base class, flags, args, and post-creation steps
- License 许可
- MIT
- 最近更新
- 2026-11-15
- Stars
- ★ 3
- Forks
- 1
01 前言 Front Matter
- name
- add-oclif-command
- description
- Add a new OCLIF command to a CLI package with proper base class, flags, args, and post-creation steps
- disable-model-invocation
- true
03 SKILL.md 正文
Add a New OCLIF Command
Guided workflow to add a command to an existing CLI package.
Step 1: Gather Info
Ask the user for:
- Target CLI package: cli, dill-cli, repopo, or sort-tsconfig
- Command name: e.g.,
statusorgit/status(slash = topic nesting) - Description: one-line summary
- Base class:
CommandWithConfig(default) orGitCommand(for git operations) — both from@tylerbu/cli-api - Flags and args: what inputs does the command need?
Step 2: Create the Command File
Create packages/<pkg>/src/commands/<name>.ts:
import { Args, Flags } from "@oclif/core";
import { CommandWithConfig } from "@tylerbu/cli-api";
export default class CommandName extends CommandWithConfig<typeof CommandName> {
public static override readonly description = "Description here";
public static override readonly flags = {
// Add flags here
...CommandWithConfig.flags,
};
public static override readonly args = {
// Add args here
};
public override async run(): Promise<void> {
const { args, flags } = this;
// Implementation
}
}
For git commands, use GitCommand instead — it provides this.git (simple-git instance).
Step 3: Build and Verify
# Compile
pnpm nx run <pkg>:build:compile
# Test with dev binary
./packages/<pkg>/bin/dev.js <command> --help
# Regenerate manifest
pnpm nx run <pkg>:build:manifest
# Regenerate README
pnpm nx run <pkg>:build:readme
Step 4: Update Snapshots (if applicable)
# Regenerate command snapshots
./packages/<pkg>/bin/dev.js snapshot:generate --filepath test/commands/__snapshots__/commands.json
# Verify snapshots match
./packages/<pkg>/bin/dev.js snapshot:compare --filepath test/commands/__snapshots__/commands.json
Step 5: Final Checks
# Full build to ensure everything links
pnpm nx run <pkg>:build
# Run tests
pnpm nx run <pkg>:test
# Policy check
./packages/repopo/bin/dev.js check
Conventions
- Use tabs for indentation
- Keep commands focused — one responsibility per command
- Use
this.log()for stdout,this.warn()for warnings,this.error()for fatal errors (exits) - Prefer flags over positional args for optional inputs
- Always spread
...BaseClass.flagsto inherit base flags
04 同仓库更多 Skills
scaffold-package
Scaffold a new package in the monorepo with correct conventions, configs, and policy compliance
release-check
Validate release readiness - changesets, policy compliance, build, test, and dependency sync
pr-changeset-check
Check if PR has appropriate changesets before creating
post-edit-conventions
Monorepo coding conventions to follow when writing or editing code in this repository
oclif-command-guide
Reference for OCLIF command patterns, base classes, and conventions used in CLI packages
nx-task-guide
Reference for Nx task architecture, orchestration patterns, and how to add or modify build tasks