Skip to content

Comments

feat: add CLI JSON documentation generation#372

Merged
josecelano merged 5 commits intomainfrom
cli-json-docs
Feb 20, 2026
Merged

feat: add CLI JSON documentation generation#372
josecelano merged 5 commits intomainfrom
cli-json-docs

Conversation

@josecelano
Copy link
Member

Overview

This PR adds automatic CLI documentation generation in machine-readable JSON format. This enables AI agents, documentation generators, and IDE integrations to easily understand and interact with the CLI without needing to run commands with --help or parse source code.

What's Added

New docs Command

Generate comprehensive CLI documentation in JSON format:

# Generate to stdout (pipeable)
torrust-tracker-deployer docs

# Save to file
torrust-tracker-deployer docs docs/cli/commands.json

Pre-Generated Documentation

A complete, up-to-date CLI documentation file is maintained at:

  • Location: docs/cli/commands.json
  • Format: Structured JSON with commands, arguments, descriptions, and metadata
  • Version: Automatically includes CLI version information

Why This Matters

For AI Agents:

  • Instantly understand all available commands and their arguments
  • No need for trial-and-error with --help flags
  • Complete command structure in a single file

For Documentation Generators:

  • Use as input for automated reference documentation
  • Keep docs in sync with actual CLI implementation

For IDE Integrations:

  • Enable autocomplete and inline help
  • Provide command suggestions as users type

For Version Control:

  • Track CLI interface changes over time
  • Catch unintended breaking changes in code review

JSON Format

The generated documentation includes:

{
  "format": "cli-documentation",
  "format_version": "1.0",
  "cli": {
    "name": "torrust-tracker-deployer",
    "version": "0.1.0",
    "commands": [
      {
        "name": "provision",
        "description": "...",
        "arguments": [...],
        "subcommands": [...]
      }
    ]
  }
}

Enhanced Help Text

As part of this work, all CLI command help text has been significantly improved with:

  • State transitions: Shows what state changes occur (e.g., Created → Provisioned)
  • Workflow position: Indicates where command fits in deployment workflow (Step X of 8)
  • Next steps: Actionable guidance on what to do after command completes
  • Clear exclusions: Explicitly states what the command does NOT do
  • Execution estimates: Expected duration for long-running commands

All 16 commands now provide comprehensive guidance to help users understand the deployment workflow.

Usage Example

# Generate documentation
cargo run -- docs docs/cli/commands.json

# Query with jq
jq '.cli.commands[].name' docs/cli/commands.json

# Use in AI agent context
cat docs/cli/commands.json | ai-agent "explain deployment workflow"

Testing

  • ✅ All 412 tests passing
  • ✅ JSON documentation generates successfully
  • ✅ Help text renders correctly in terminal
  • ✅ All linters passing

Documentation

  • User guide: docs/user-guide/commands/docs.md
  • Pre-generated file: docs/cli/commands.json
  • Agent skill: .github/skills/regenerate-cli-docs/skill.md

- Add infrastructure layer for CLI documentation generation
  - schema_builder: Extract command metadata from clap structures
  - generator: Generate JSON documentation with format metadata
- Add presentation controller for docs command
  - Handler for docs command with stdout/file output support
  - Error types for docs command failures
- Wire docs command into CLI and dispatch router
- Update error handling to support docs command
- Add comprehensive help text for all CLI commands
  - Workflow position and state transitions
  - Next steps and usage scenarios
  - Service access endpoints and verification steps
- Add user guide for docs command (docs/user-guide/commands/docs.md)
  - Explain two output modes (stdout vs file)
  - Document usage scenarios (IDE integration, CI/CD validation)
  - Provide JSON structure examples
- Add generated CLI documentation JSON (docs/cli/commands.json)
  - Complete command metadata with descriptions and help text
  - Argument specifications with types and requirements
  - Workflow position and next steps for each command
- Update commands README with docs command entry
- Update docs README with CLI documentation section
- Add new agent skill for regenerating CLI documentation
  - Automated workflow to run docs command
  - Save output to docs/cli/commands.json
  - Validate JSON and stage changes
- Update AGENTS.md with skill reference
  - Add to auto-invoke skills table
  - Include regenerating CLI docs row
- Add pipeable to project dictionary (cspell)
- Update .gitignore for CLI docs directory
- Update schemas README with CLI schema reference
- Update roadmap with CLI JSON documentation completion
- Escape square brackets in workflow position indicators
- Escape angle brackets in command placeholders
- Fixes 10 rustdoc warnings about unresolved links and unclosed HTML tags
- Regenerate CLI documentation JSON with fixes
@josecelano
Copy link
Member Author

ACK d1e1a14

@josecelano josecelano merged commit 6e8c7bc into main Feb 20, 2026
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant