Command Structure
Commands in doc-kit are modules that export a command object conforming to theCommand interface:
- name - The command name used in the CLI (e.g.,
generate,interactive) - description - A short description shown in help text
- options - An object mapping option names to their definitions
- action - The async function that executes when the command is run
Creating a New Command
Step 1: Create the Command File
Create a new file inbin/commands/ with your command name:
Step 2: Register the Command
Add your command to the exports inbin/commands/index.mjs:
Step 3: CLI Auto-Loading
The CLI inbin/cli.mjs automatically loads commands from bin/commands/index.mjs, so no changes are needed there if you followed step 2.
Command Options
Options define the flags and parameters your command accepts. Each option has:Defining Options
Flag Syntax
The flag syntax follows standard CLI conventions:<value>- Required argument[value]- Optional argument<values...>- Variadic (multiple values)[values...]- Optional variadic
Option Types
Theprompt field configures how options are presented in interactive mode.
Text Input
Single-line text input:Confirmation
Yes/no confirmation:Select (Single Choice)
Single choice from a list:Multi-Select (Multiple Choices)
Multiple choices from a list:Interactive Prompts
Theinteractive command automatically uses the prompt configuration from your options. When users run:
- Select a command
- Answer all prompts for that command’s options
Prompt Configuration
All prompt types support these fields:- message - Question to ask the user (required)
- type - Input type:
text,confirm,select, ormultiselect(required) - initialValue - Default value (optional)
- required - Whether the field must have a value (optional, default: false)
- text:
variadic- Allow multiple values (default: false) - select/multiselect:
options- Array of{ label, value }objects
Making Options Interactive-Friendly
Always provide helpful messages and sensible defaults:Complete Example
Here’s a complete command that validates documentation links:Usage
Best Practices
DO: Provide Helpful Descriptions
DO: Use Smart Defaults
DO: Validate Input
DON’T: Use Unclear Messages
DON’T: Forget Error Handling
Next Steps
Architecture
Understand how commands integrate with the generator system
Comparators
Learn how to create build comparators for CI/CD