|
1 | 1 | # Configuration Documentation Generator
|
2 | 2 |
|
3 |
| -A tool that automatically generates comprehensive Markdown documentation for Stacks node TOML configuration options. The documentation is extracted directly from Rust source code comments and generates a complete configuration reference. |
| 3 | +This tool automatically generates markdown documentation from Rust configuration structs by extracting specially formatted doc comments. |
4 | 4 |
|
5 | 5 | ## Quick Start
|
6 | 6 |
|
@@ -54,6 +54,242 @@ For each configuration field, it extracts:
|
54 | 54 | - **Primary**: `docs/generated/configuration-reference.md` - Complete configuration reference
|
55 | 55 | - **Intermediate**: `target/doc-generation/extracted-config-docs.json` - Raw extracted data
|
56 | 56 |
|
| 57 | +## Annotation Syntax Guide |
| 58 | + |
| 59 | +### Overview |
| 60 | + |
| 61 | +The generator processes doc comments with a structured annotation format: |
| 62 | + |
| 63 | +```rust |
| 64 | +/// [Description text in Markdown format] |
| 65 | +/// --- |
| 66 | +/// @annotation_name: value |
| 67 | +/// @another_annotation: value |
| 68 | +pub field_name: Type, |
| 69 | +``` |
| 70 | + |
| 71 | +### General Structure |
| 72 | + |
| 73 | +- **Description**: Standard Markdown text before the `---` separator |
| 74 | +- **Separator**: Three dashes (`---`) separate description from annotations |
| 75 | +- **Annotations**: Key-value pairs starting with `@`, each on its own line |
| 76 | + |
| 77 | +### Supported Annotations |
| 78 | + |
| 79 | +#### `@default: <value>` |
| 80 | +Specifies the default value for the field. |
| 81 | +- **Value Type**: String |
| 82 | +- **Multiline Support**: Yes (all modes) |
| 83 | +- **Examples**: |
| 84 | + ```rust |
| 85 | + /// @default: `None` |
| 86 | + /// @default: `"localhost:8080"` |
| 87 | + /// @default: | |
| 88 | + /// Complex multi-line |
| 89 | + /// default value |
| 90 | + ``` |
| 91 | + |
| 92 | +#### `@notes: <content>` |
| 93 | +Additional notes or explanations, rendered as a bulleted list. |
| 94 | +- **Value Type**: String (parsed into list items) |
| 95 | +- **Multiline Support**: Yes (all modes) |
| 96 | +- **List Processing**: Lines starting with `-`, `*`, or `•` become list items |
| 97 | +- **Examples**: |
| 98 | + ```rust |
| 99 | + /// @notes: Single line note |
| 100 | + /// @notes: |
| 101 | + /// - First bullet point |
| 102 | + /// - Second bullet point |
| 103 | + /// @notes: | |
| 104 | + /// Complex formatting with |
| 105 | + /// preserved line breaks |
| 106 | + ``` |
| 107 | + |
| 108 | +#### `@deprecated: <message>` |
| 109 | +Marks a field as deprecated with an optional message. |
| 110 | +- **Value Type**: String |
| 111 | +- **Multiline Support**: Yes (all modes) |
| 112 | +- **Examples**: |
| 113 | + ```rust |
| 114 | + /// @deprecated: Use new_field instead |
| 115 | + /// @deprecated: | |
| 116 | + /// This field will be removed in v3.0. |
| 117 | + /// Migrate to the new configuration system. |
| 118 | + ``` |
| 119 | + |
| 120 | +#### `@toml_example: <example>` |
| 121 | +Provides TOML configuration examples. |
| 122 | +- **Value Type**: String |
| 123 | +- **Multiline Support**: Yes (all modes) |
| 124 | +- **Rendering**: Displayed in `<pre><code>` blocks in markdown tables |
| 125 | +- **Examples**: |
| 126 | + ```rust |
| 127 | + /// @toml_example: key = "value" |
| 128 | + /// @toml_example: | |
| 129 | + /// [section] |
| 130 | + /// key = "value" |
| 131 | + /// nested = { a = 1, b = 2 } |
| 132 | + ``` |
| 133 | + |
| 134 | +#### `@required: <boolean>` |
| 135 | +Indicates whether the field is mandatory. |
| 136 | +- **Value Type**: Boolean (flexible parsing) |
| 137 | +- **Default**: `false` if annotation is omitted |
| 138 | +- **Supported Values**: |
| 139 | + - `true`, `True`, `TRUE`, `yes`, `Yes`, `YES`, `1` → `true` |
| 140 | + - `false`, `False`, `FALSE`, `no`, `No`, `NO`, `0` → `false` |
| 141 | + - Invalid values default to `false` |
| 142 | +- **Examples**: |
| 143 | + ```rust |
| 144 | + /// @required: true |
| 145 | + /// @required: yes |
| 146 | + /// @required: false |
| 147 | + ``` |
| 148 | + |
| 149 | +#### `@units: <unit>` |
| 150 | +Specifies the unit of measurement for the field. |
| 151 | +- **Value Type**: String |
| 152 | +- **Multiline Support**: Yes (all modes) |
| 153 | +- **Constant References**: Supports `[`CONSTANT_NAME`]` syntax |
| 154 | +- **Examples**: |
| 155 | + ```rust |
| 156 | + /// @units: milliseconds |
| 157 | + /// @units: sats/vByte |
| 158 | + ``` |
| 159 | + |
| 160 | +### Multiline Content Support |
| 161 | + |
| 162 | +All annotations support three multiline modes: |
| 163 | + |
| 164 | +#### Default Literal-like Mode |
| 165 | +Content preserves newlines and relative indentation within the annotation block. |
| 166 | + |
| 167 | +```rust |
| 168 | +/// @notes: |
| 169 | +/// First line with base indentation |
| 170 | +/// Second line more indented |
| 171 | +/// Third line back to base |
| 172 | +/// Fourth line very indented |
| 173 | +``` |
| 174 | + |
| 175 | +**Output preserves relative indentation**: |
| 176 | +``` |
| 177 | +First line with base indentation |
| 178 | + Second line more indented |
| 179 | +Third line back to base |
| 180 | + Fourth line very indented |
| 181 | +``` |
| 182 | + |
| 183 | +#### Literal Block Style (`|`) |
| 184 | +Exact preservation of newlines and relative indentation. Uses "clip" chomping (single trailing newline preserved). |
| 185 | + |
| 186 | +```rust |
| 187 | +/// @toml_example: | |
| 188 | +/// [network] |
| 189 | +/// bind = "0.0.0.0:20444" |
| 190 | +/// # Indented comment |
| 191 | +/// timeout = 30 |
| 192 | +``` |
| 193 | + |
| 194 | +**Output**: |
| 195 | +``` |
| 196 | +[network] |
| 197 | +bind = "0.0.0.0:20444" |
| 198 | + # Indented comment |
| 199 | +timeout = 30 |
| 200 | +``` |
| 201 | + |
| 202 | +#### Folded Block Style (`>`) |
| 203 | +Folds lines into paragraphs with intelligent spacing. More-indented lines preserved as literal blocks. |
| 204 | + |
| 205 | +```rust |
| 206 | +/// @notes: > |
| 207 | +/// This is a long paragraph that will be |
| 208 | +/// folded into a single line with spaces |
| 209 | +/// between the original line breaks. |
| 210 | +/// |
| 211 | +/// This is a second paragraph after a blank line. |
| 212 | +/// |
| 213 | +/// This indented block will be preserved |
| 214 | +/// exactly as written, like code. |
| 215 | +/// |
| 216 | +/// Back to normal folded paragraph text. |
| 217 | +``` |
| 218 | + |
| 219 | +**Output**: |
| 220 | +``` |
| 221 | +This is a long paragraph that will be folded into a single line with spaces between the original line breaks. |
| 222 | +
|
| 223 | +This is a second paragraph after a blank line. |
| 224 | +
|
| 225 | + This indented block will be preserved |
| 226 | + exactly as written, like code. |
| 227 | +
|
| 228 | +Back to normal folded paragraph text. |
| 229 | +``` |
| 230 | + |
| 231 | +### Same-line Content |
| 232 | + |
| 233 | +Content can start immediately after the colon for default multiline mode: |
| 234 | + |
| 235 | +```rust |
| 236 | +/// @default: immediate content |
| 237 | +/// @notes: Content that starts immediately |
| 238 | +/// and continues on the next line |
| 239 | +``` |
| 240 | + |
| 241 | +For literal (`|`) and folded (`>`) modes, content must start on the next line: |
| 242 | + |
| 243 | +```rust |
| 244 | +/// @notes: | |
| 245 | +/// Content starts here on the next line |
| 246 | +/// All content must be indented on subsequent lines |
| 247 | +/// @deprecated: > |
| 248 | +/// Folded content also starts on the next line |
| 249 | +/// and will be joined appropriately |
| 250 | +``` |
| 251 | + |
| 252 | +### Complete Example |
| 253 | + |
| 254 | +```rust |
| 255 | +/// Timeout duration for network connections. |
| 256 | +/// |
| 257 | +/// This setting controls how long the node will wait for network operations |
| 258 | +/// to complete before timing out. Setting this too low may cause connection |
| 259 | +/// failures on slow networks. |
| 260 | +/// --- |
| 261 | +/// @default: [`DEFAULT_NETWORK_TIMEOUT`] |
| 262 | +/// @required: true |
| 263 | +/// @units: milliseconds |
| 264 | +/// @notes: |
| 265 | +/// - Must be greater than 0 |
| 266 | +/// - Recommended range: 1000-30000 |
| 267 | +/// - Higher values needed for slow connections |
| 268 | +/// @toml_example: | |
| 269 | +/// [network] |
| 270 | +/// timeout = 15000 # 15 seconds |
| 271 | +/// @deprecated: > |
| 272 | +/// Use the new `connection_timeout` setting instead. |
| 273 | +/// This field will be removed in version 3.0. |
| 274 | +pub timeout_ms: u64, |
| 275 | +``` |
| 276 | + |
| 277 | +### Best Practices |
| 278 | + |
| 279 | +1. **Choose the right multiline mode**: |
| 280 | + - Default mode: General text with preserved formatting |
| 281 | + - Literal (`|`): Code examples, exact formatting required |
| 282 | + - Folded (`>`): Documentation prose, automatic paragraph wrapping |
| 283 | + |
| 284 | +2. **Use constant references in `@default` when appropriate** |
| 285 | + |
| 286 | +### Integration with Rust Documentation |
| 287 | + |
| 288 | +This system integrates with standard Rust documentation tools: |
| 289 | +- Doc comments remain valid for `rustdoc` |
| 290 | +- Annotations are ignored by standard documentation generators |
| 291 | +- Full compatibility with existing documentation workflows |
| 292 | + |
57 | 293 | ## Adding New Configuration Structs
|
58 | 294 |
|
59 | 295 | ### 1. Update the Target List
|
|
0 commit comments