Commit 3e5564d
Phase 4: Add CLI examples extractor with 208 categorized examples
Implemented automatic extraction of real CLI command examples from Java
test files, providing comprehensive usage patterns for documentation.
## What We Built
**CLI Examples Extractor** (docs/scripts/extract-cli-examples.py):
- Parses all *CmdTest.java files to extract exec() calls
- Captures command syntax, arguments, and test context
- Identifies Response types for output formatting
- Categorizes examples: success (72.6%), error (19.7%), edge_case (7.7%)
- Generates structured JSON output with complete metadata
**Extracted Examples** (docs/cli-examples.json):
- 208 total command examples from 23 test files
- 151 success examples for standard documentation
- 41 error examples for troubleshooting guides
- 16 edge case examples for comprehensive docs
- Coverage across 22 command families
## Example Distribution by Family
Top families:
- pipelines (24), studios (23), actions (20), runs (16), compute-envs (16),
workspaces (14), organizations (13), participants (12), datasets (11)
All families:
- teams (9), members (8), credentials (8), labels (7), secrets (6),
launch (5), info (4), data-links (3), team-members (3), metrics (2),
task (2), tasks (1), collaborators (1)
## Key Features
**Automatic Categorization**:
- Success: Real-world usage patterns with expected outcomes
- Error: Failed authentication, not found, invalid input scenarios
- Edge case: Empty lists, conflicting parameters, null values
**Flexible Filtering**:
```python
# Docs repo can filter by category
success_examples = [ex for ex in examples if ex['category'] == 'success']
error_examples = [ex for ex in examples if ex['category'] == 'error']
```
**Rich Metadata**:
- Full command string and parsed arguments
- Test method name and file location with line numbers
- Response type identification for output formatting
- Command family grouping for organization
## Docs Repo Integration
The docs repository can now:
1. Fetch both cli-metadata.json and cli-examples.json from releases
2. Filter examples by category (success for standard docs)
3. Combine metadata + examples → comprehensive reference pages
4. Generate markdown with real command invocations
5. Track example changes across CLI versions
Example workflow integration:
```yaml
# .github/workflows/update-cli-docs.yml
- name: Fetch CLI data
run: |
curl -o cli-metadata.json ${metadata_url}
curl -o cli-examples.json ${examples_url}
- name: Generate docs
run: |
python scripts/generate-cli-docs.py \
--metadata cli-metadata.json \
--examples cli-examples.json \
--filter-category success
```
## Benefits
1. **Always in sync**: Extracted from actual test code that validates CLI
2. **Comprehensive**: 208 usage patterns across 22 command families
3. **Automatic updates**: Re-extraction captures new examples when tests added
4. **Flexible filtering**: Category system for different doc purposes
5. **Structured data**: JSON format easy to consume by generators
6. **Version tracking**: Committed for change history
## Example Commands Extracted
Pagination: tw runs list --offset 1 --max 2
CRUD operations: tw runs delete -i 5dAZoXrcmZXRO4
Scoped commands: tw members list -o organization1
## Design Decisions
**Why from test files?**
- Real, validated command invocations
- Test assertions guarantee correctness
- Realistic parameter values and IDs
- Automatically updated with tests
**Why categorize?**
- Standard docs show success only
- Error examples for troubleshooting
- Edge cases for comprehensive docs
- Filtering provides maximum flexibility
**Updated progress.md** with complete Phase 4 documentation including:
- Extraction statistics and distribution tables
- Integration guide for docs repository
- Example filtering strategies with code samples
- Complete usage documentation
This completes the tower-cli side of the automation pipeline. The docs
repository can now receive both cli-metadata.json (structure) and
cli-examples.json (usage) to generate comprehensive CLI documentation.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>1 parent a83ca34 commit 3e5564d
3 files changed
Lines changed: 4767 additions & 2 deletions
0 commit comments