Overview
The CLI layer is the entry point formint-tsdocs, responsible for parsing user commands and initiating the documentation generation process. Built on @rushstack/ts-command-line, it provides a robust, typed command-line interface.
Entry Point:
src/start.ts creates the CLI instance and runs the parserComponent Architecture
- start.ts
- ApiDocumenterCommandLine
- BaseAction
- MarkdownAction
The Executable Entry PointResponsibilities:
src/start.ts
- Display version banner
- Create CLI parser instance
- Execute command and handle errors
Execution Flow
Detailed Flow Breakdown
1. Command Invocation
1. Command Invocation
User runs the command:
- Binary executes
lib/start.js - Version banner is displayed
DocumenterCliinstance is created
2. CLI Parsing
2. CLI Parsing
DocumenterCli.executeAsync() processes the command:- Identifies action:
markdown - Validates required parameters
- Parses all flags and values
- Routes to
MarkdownAction.onExecuteAsync()
3. API Model Building
3. API Model Building
BaseAction.buildApiModel() loads the API data:4. Documenter Instantiation
4. Documenter Instantiation
MarkdownAction creates and configures the documenter:5. Generation Handoff
5. Generation Handoff
Control passes to the generation layer:The CLI layer’s work is complete - the generation layer takes over.
Parameter Validation
The CLI layer ensures all parameters are valid before proceeding:Error Handling
Common errors caught at the CLI layer:| Error | Cause | Solution |
|---|---|---|
| Input folder not found | Invalid -i path | Verify path exists |
| No .api.json files | Wrong input folder | Run api-extractor first |
| Invalid docs.json | Malformed JSON | Validate JSON syntax |
| Permission denied | Output folder protected | Check file permissions |
Extending the CLI
Adding a New Parameter
1
Define in Action
2
Pass to Documenter
3
Update Interface
4
Use in Generation
Use the new option in
MarkdownDocumenter logicAdding a New Command
To add a new command (e.g.,yaml):
- Create
YamlAction.tsextendingBaseAction - Implement
onExecuteAsync() - Register in
ApiDocumenterCommandLine._populateActions()

