|
| 1 | +# lion |
| 2 | + |
| 3 | +Documentation extraction tool for Go code that generates markdown files from special comments. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +lion scans Go source code for special `//lion:topic-name` comments and generates organized markdown documentation. This allows you to build a book-like documentation structure by adding comments throughout your codebase that contribute to different chapters/topics. |
| 8 | + |
| 9 | +## Installation |
| 10 | + |
| 11 | +```bash |
| 12 | +go install github.com/neongreen/mono/lion@latest |
| 13 | +``` |
| 14 | + |
| 15 | +## Usage |
| 16 | + |
| 17 | +### Add Documentation Comments |
| 18 | + |
| 19 | +Add `//lion:topic-name` comments to your Go code: |
| 20 | + |
| 21 | +```go |
| 22 | +//lion:architecture This is the main entry point for the application. |
| 23 | +//lion:architecture It handles initialization and routing. |
| 24 | +func main() { |
| 25 | + // ... |
| 26 | +} |
| 27 | + |
| 28 | +//lion:api The Config struct holds application configuration. |
| 29 | +//lion:api Fields can be loaded from environment variables or config files. |
| 30 | +type Config struct { |
| 31 | + Port int |
| 32 | + Debug bool |
| 33 | +} |
| 34 | +``` |
| 35 | + |
| 36 | +### Generate Documentation |
| 37 | + |
| 38 | +```bash |
| 39 | +# Generate docs from current directory to ./docs |
| 40 | +lion generate |
| 41 | + |
| 42 | +# Specify input directory and output directory |
| 43 | +lion generate ./myproject --output ./documentation |
| 44 | + |
| 45 | +# List all topics found in code |
| 46 | +lion topics |
| 47 | +``` |
| 48 | + |
| 49 | +### Output |
| 50 | + |
| 51 | +The tool generates: |
| 52 | +- One markdown file per topic (e.g., `architecture.md`, `api.md`) |
| 53 | +- An `index.md` file listing all topics |
| 54 | +- Each entry includes source file reference for traceability |
| 55 | + |
| 56 | +## Comment Format |
| 57 | + |
| 58 | +lion supports three comment formats: |
| 59 | + |
| 60 | +### 1. Single-line format (marker first) |
| 61 | + |
| 62 | +``` |
| 63 | +//lion:topic-name Optional content describing this code element |
| 64 | +``` |
| 65 | + |
| 66 | +- **topic-name**: Hyphen-separated identifier (becomes filename) |
| 67 | +- **Content**: Optional markdown-formatted text |
| 68 | +- Multiple consecutive `//lion:topic` lines are combined into one entry |
| 69 | + |
| 70 | +### 2. Block comment format |
| 71 | + |
| 72 | +```go |
| 73 | +/*lion:topic-name |
| 74 | +Multi-line content can go here |
| 75 | +without repeating the topic name. |
| 76 | +This makes documentation cleaner. |
| 77 | +*/ |
| 78 | +``` |
| 79 | + |
| 80 | +- **topic-name**: Specified once at the beginning |
| 81 | +- **Content**: All subsequent lines in the block comment |
| 82 | +- Cleaner for longer documentation blocks |
| 83 | + |
| 84 | +All formats can be attached to functions, types, constants, variables, and package declarations. |
| 85 | + |
| 86 | +## Example |
| 87 | + |
| 88 | +Marker-first format (recommended): |
| 89 | + |
| 90 | +```go |
| 91 | +//lion:getting-started |
| 92 | +// |
| 93 | +// lion is a documentation extraction tool. |
| 94 | +// Add lion comments to generate markdown docs. |
| 95 | +// This is the cleanest syntax for multi-line docs. |
| 96 | +package main |
| 97 | + |
| 98 | +//lion:architecture |
| 99 | +// |
| 100 | +// The main function initializes the app. |
| 101 | +// It handles setup and configuration. |
| 102 | +func main() { |
| 103 | + // ... |
| 104 | +} |
| 105 | +``` |
| 106 | + |
| 107 | +Single-line format: |
| 108 | + |
| 109 | +```go |
| 110 | +//lion:getting-started lion is a documentation extraction tool. |
| 111 | +//lion:getting-started Add lion comments to generate markdown docs. |
| 112 | +package main |
| 113 | + |
| 114 | +//lion:architecture The main function initializes the app. |
| 115 | +func main() { |
| 116 | + // ... |
| 117 | +} |
| 118 | +``` |
| 119 | + |
| 120 | +Block comment format: |
| 121 | + |
| 122 | +```go |
| 123 | +/*lion:getting-started |
| 124 | +lion is a documentation extraction tool. |
| 125 | +Add lion comments to generate markdown docs. |
| 126 | +No need to repeat the topic on each line. |
| 127 | +*/ |
| 128 | +package main |
| 129 | + |
| 130 | +/*lion:architecture |
| 131 | +The main function initializes the app. |
| 132 | +It handles setup and configuration. |
| 133 | +*/ |
| 134 | +func main() { |
| 135 | + // ... |
| 136 | +} |
| 137 | +``` |
| 138 | + |
| 139 | +Running `lion generate` creates: |
| 140 | +- `docs/getting-started.md` |
| 141 | +- `docs/architecture.md` |
| 142 | +- `docs/index.md` |
| 143 | + |
| 144 | +## Status |
| 145 | + |
| 146 | +**Alpha** - Core functionality works. Comment format and CLI may change. |
| 147 | + |
| 148 | +## Self-Documentation |
| 149 | + |
| 150 | +lion uses itself to generate its own documentation! The `docs/` directory contains markdown files extracted from lion comments in the source code. |
| 151 | + |
| 152 | +To regenerate the documentation: |
| 153 | +```bash |
| 154 | +./regenerate-docs.sh |
| 155 | +``` |
| 156 | + |
| 157 | +Or manually: |
| 158 | +```bash |
| 159 | +go run . generate . --output ./docs |
| 160 | +``` |
0 commit comments