-
-
Notifications
You must be signed in to change notification settings - Fork 0
Documentation System
Joao Palma edited this page Oct 27, 2025
·
3 revisions
← Script Management | Home | Team Workflows →
- Overview
- Inline Documentation
- Markdown Documentation
- Documentation Commands
- Best Practices
- Examples
- Next Steps
DotRun features a comprehensive documentation system:
-
Inline Docs: Embedded documentation in scripts using
### DOCblocks -
Markdown Files: Standalone documentation in the
docs/directory -
Auto-rendering: View formatted docs with
dr helpcommand - Cross-references: Link between scripts and documentation
Every script should include a ### DOC block:
#!/usr/bin/env bash
### DOC
# Script Name - Brief Description
#
# Detailed description of what this script does,
# why it exists, and when to use it.
#
# Usage: dr scriptname [options] [arguments]
#
# Options:
# -h, --help Show this help message
# -v, --verbose Enable verbose output
#
# Arguments:
# arg1 Description of first argument
# arg2 Optional second argument
#
# Examples:
# dr scriptname arg1
# dr scriptname -v arg1 arg2
### DOC
# Script implementation...- Script name and brief description
- Usage syntax
- At least one example
### DOC
# Script Name - Brief description
#
# Description:
# Detailed explanation of the script's purpose
#
# Usage: dr scriptname [options] arguments
#
# Options:
# -h, --help Show help
# -f, --force Force operation
# -n, --dry-run Preview changes
#
# Arguments:
# input Input file or directory
# output Output location (optional)
#
# Examples:
# dr scriptname input.txt
# dr scriptname -f input.txt output.txt
# dr scriptname --dry-run directory/
#
# Environment Variables:
# CONFIG_PATH Path to configuration (default: ~/.config)
# API_KEY Required API key for external service
#
# Dependencies:
# - curl: For API requests
# - jq: For JSON processing
#
# Exit Codes:
# 0 Success
# 1 General error
# 2 Invalid arguments
# 3 Missing dependencies
#
# Notes:
# - Requires internet connection
# - Creates backup before processing
#
# See Also:
# - dr related-script
# - Documentation: docs/detailed-guide.md
### DOC### DOC
# Category: deployment
# Subcategory: kubernetes
# Tags: k8s, deploy, production
#
# Deploy to Kubernetes - Production deployment script
# ...
### DOC### DOC
# Script: deploy-production
# Version: 2.1.0
# Author: Team Name
# Last Modified: 2024-01-15
#
# Changelog:
# 2.1.0 - Add multi-region support
# 2.0.0 - Breaking: New config format
# 1.0.0 - Initial release
# ...
### DOC### DOC
# Examples:
#
# Basic usage:
# dr deploy-app myapp
#
# With environment:
# ENV=staging dr deploy-app myapp
#
# Full options:
# dr deploy-app \
# --environment production \
# --region us-east-1 \
# --version 1.2.3 \
# --rollback-on-failure \
# myapp
#
# Using config file:
# dr deploy-app --config deploy.yml myapp
### DOC# Create new documentation
dr doc create getting-started
# Create with category
dr doc create guides/deployment
# Create from template
dr doc create api-guide --template=api-doc~/.config/dotrun/docs/
├── README.md # Main documentation index
├── getting-started.md # Quick start guide
├── guides/ # Categorized guides
│ ├── deployment.md
│ ├── testing.md
│ └── troubleshooting.md
├── references/ # Reference documentation
│ ├── api.md
│ └── configuration.md
└── examples/ # Example documentation
├── basic-workflows.md
└── advanced-usage.md
Create a documentation template:
# {{TITLE}}
## Overview
Brief description of the topic.
## Table of Contents
- [Prerequisites](#prerequisites)
- [Getting Started](#getting-started)
- [Configuration](#configuration)
- [Usage](#usage)
- [Examples](#examples)
- [Troubleshooting](#troubleshooting)
- [Related Documentation](#related-documentation)
## Prerequisites
What you need before starting.
## Getting Started
Step-by-step introduction.
## Configuration
Configuration options and setup.
## Usage
Detailed usage instructions.
## Examples
### Example 1: Basic Usage
```bash
# Example command
dr example-script
```# Advanced example
dr example-script --option valueCommon issues and solutions.
- Related Guide
- Script:
dr help scriptname
### Linking Scripts and Docs
Reference documentation from scripts:
```bash
### DOC
# Script Name
#
# Brief description
#
# For detailed information, see:
# dr doc view deployment-guide
#
# Related documentation:
# - docs/guides/deployment.md
# - docs/troubleshooting.md
### DOC
Reference scripts from documentation:
## Related Scripts
- `dr deploy-staging` - Deploy to staging environment
- `dr deploy-production` - Deploy to production
- `dr rollback` - Rollback deployment
Run `dr help <script>` for detailed usage.# View script documentation
dr help scriptname
dr help git/cleanup
# View markdown documentation
dr doc view getting-started
dr doc view guides/deployment
# Open in browser (if glow installed)
dr doc view --browser api-guide# List all documentation
dr doc list
# Search documentation
dr doc search "deployment"
dr doc search "api" --category guides
# Edit documentation
dr doc edit getting-started
# Remove documentation
dr doc rm outdated-guideGenerate an index:
#!/usr/bin/env bash
# generate-doc-index.sh
cat >~/.config/dotrun/docs/README.md <<'EOF'
# DotRun Documentation
## Quick Links
- [Getting Started](getting-started.md)
- [User Guide](guides/user-guide.md)
- [Script Reference](references/scripts.md)
## Documentation by Category
EOF
# Add guides
echo "### Guides" >>~/.config/dotrun/docs/README.md
find ~/.config/dotrun/docs/guides -name "*.md" | sort | while read -r doc; do
name=$(basename "$doc" .md)
echo "- [${name^}](guides/$name.md)" >>~/.config/dotrun/docs/README.md
done
# Add references
echo -e "\n### References" >>~/.config/dotrun/docs/README.md
find ~/.config/dotrun/docs/references -name "*.md" | sort | while read -r doc; do
name=$(basename "$doc" .md)
echo "- [${name^}](references/$name.md)" >>~/.config/dotrun/docs/README.md
doneUse consistent documentation format:
### DOC
# [CATEGORY/]SCRIPT_NAME - Brief description (one line)
#
# [Empty line]
# Detailed description paragraph.
# Can be multiple lines.
#
# [Empty line]
# Usage: dr scriptname [options] <required> [optional]
#
# [Rest of documentation sections]
### DOCProvide realistic examples:
# Examples:
# # Deploy to staging with defaults
# dr deploy staging
#
# # Deploy specific version to production
# dr deploy production --version 1.2.3
#
# # Dry run to see what would happen
# dr deploy production --dry-runAlways document dependencies:
# Dependencies:
# Required:
# - git: Version control operations
# - curl: API requests
# Optional:
# - jq: JSON pretty printing (falls back to python)
# - notify-send: Desktop notificationsDocument common errors:
# Troubleshooting:
# Error: "API_KEY not set"
# Solution: Export API_KEY environment variable
#
# Error: "Connection refused"
# Solution: Check VPN connection and retry
#
# Error: "Permission denied"
# Solution: Run with sudo or check file permissionsLink related resources:
# See Also:
# Scripts:
# - dr deploy-staging (test deployment first)
# - dr rollback (revert deployment)
# Documentation:
# - docs/deployment-guide.md
# - docs/troubleshooting.md
# External:
# - https://example.com/api-docs#!/usr/bin/env bash
### DOC
# deploy/production - Deploy application to production
#
# Deploys the application to production environment with
# health checks, rollback capability, and notifications.
#
# Usage: dr deploy/production [options] <version>
#
# Options:
# -h, --help Show this help
# -f, --force Skip confirmation
# -n, --dry-run Preview deployment
# --no-health-check Skip health checks
# --rollback-on-failure Auto rollback if health check fails
#
# Arguments:
# version Version tag to deploy (e.g., v1.2.3)
#
# Examples:
# # Deploy specific version
# dr deploy/production v1.2.3
#
# # Deploy with auto-rollback
# dr deploy/production --rollback-on-failure v1.2.3
#
# # Preview deployment
# dr deploy/production --dry-run v1.2.3
#
# Environment Variables:
# DEPLOY_KEY SSH key for deployment (required)
# SLACK_WEBHOOK Webhook for notifications (optional)
# HEALTH_TIMEOUT Health check timeout in seconds (default: 300)
#
# Dependencies:
# - ssh: Remote server access
# - curl: Health checks and notifications
# - git: Version verification
#
# Exit Codes:
# 0 Deployment successful
# 1 Deployment failed
# 2 Invalid arguments
# 3 Health check failed
# 4 Rollback performed
#
# Notes:
# - Requires VPN connection to production network
# - Creates backup before deployment
# - Logs all actions to ~/.config/dotrun/logs/deploy.log
#
# See Also:
# - dr deploy/staging (test first)
# - dr rollback/production
# - docs/deployment-guide.md
#
# Version: 3.2.1
# Maintainer: Platform Team
# Last Updated: 2024-01-15
### DOC
# Implementation...# Deployment Guide
## Overview
This guide covers the complete deployment process for our application,
including staging tests, production deployment, and rollback procedures.
## Table of Contents
- [Prerequisites](#prerequisites)
- [Staging Deployment](#staging-deployment)
- [Production Deployment](#production-deployment)
- [Health Checks](#health-checks)
- [Rollback Procedures](#rollback-procedures)
- [Troubleshooting](#troubleshooting)
## Prerequisites
Before deploying, ensure you have:
1. **Access Requirements**
- VPN connection to production network
- SSH key configured (`DEPLOY_KEY`)
- Deployment permissions in GitHub
2. **Tools Installed**
- DotRun: `dr --version`
- Git: `git --version`
- SSH: `ssh -V`
3. **Environment Variables**
```bash
export DEPLOY_KEY=~/.ssh/deploy_key
export SLACK_WEBHOOK=https://hooks.slack.com/...
```Always test in staging first:
# Deploy to staging
dr deploy/staging v1.2.3
# Run integration tests
dr test/integration staging
# Check logs
dr logs/staging --tail 100# Deploy specific version
dr deploy/production v1.2.3
# Monitor deployment
dr monitor/deployment production# Deploy with auto-rollback
dr deploy/production \
--rollback-on-failure \
--health-timeout 600 \
v1.2.3
# Blue-green deployment
dr deploy/production \
--strategy blue-green \
--switch-timeout 30 \
v1.2.3The deployment automatically runs health checks:
-
HTTP Health:
/healthendpoint returns 200 - Database: Can connect and query
- Dependencies: All services responding
- Performance: Response time under threshold
Manual health check:
dr health/production --verboseIf health checks fail with --rollback-on-failure:
- Deployment reverts automatically
- Previous version restored
- Notification sent to Slack
- Incident logged
# Rollback to previous version
dr rollback/production
# Rollback to specific version
dr rollback/production v1.2.2
# Emergency rollback (skip checks)
dr rollback/production --emergencyDeployment Hangs
# Check deployment status
dr status/deployment production
# View detailed logs
dr logs/deployment --verbose
# Force cleanup
dr cleanup/deployment productionHealth Check Failures
# Run detailed health check
dr health/production --debug
# Check specific service
dr health/production --service apiPermission Errors
# Verify SSH access
ssh -i $DEPLOY_KEY deploy@prod-server
# Check deployment permissions
dr check/permissions productionIn case of critical issues:
-
Immediate Rollback
dr rollback/production --emergency
-
Notify Team
dr notify/emergency "Production deployment failed" -
Gather Diagnostics
dr diagnose/production >incident-report.txt
-
dr deploy/staging- Deploy to staging -
dr deploy/production- Deploy to production -
dr rollback/production- Rollback production -
dr health/production- Health checks -
dr monitor/deployment- Monitor deployment -
dr logs/deployment- View deployment logs
For script-specific help, run: dr help <script-name>
## Next Steps
Master documentation to improve your workflow:
1. **Share Scripts**: Learn [Team Collaboration](Team-Collaboration.md)
2. **Develop Better Scripts**: See [Script Development](Script-Development.md)
3. **Configure Environment**: Read [Configuration Management](Configuration-Management.md)
4. **Improve Workflow**: Explore [Developer Experience](Developer-Experience.md)
5. **Study Examples**: Browse [Example Scripts](Script-Examples.md)
---
[← Script Management](Script-Management.md) | [Team Collaboration →](Team-Collaboration.md) | [Top ↑](#documentation-system)