-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoc.go
More file actions
283 lines (193 loc) · 9.07 KB
/
doc.go
File metadata and controls
283 lines (193 loc) · 9.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
// ***** AUTO GENERATED: DO NOT MODIFY *****.
// MODIFY TEMPLATE: '.doc.gtm.go'.
// See: 'https://github.com/dancsecs/gotomd'.
/*
Golang To Github Markdown Utility: gotomd
Copyright (C) 2023, 2024 Leslie Dancsecs
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
//nolint:lll // Ok.
/*
# Usage
usage: gotomd [-v | --verbose ...] [-d | --directive] [-l | --license]
[-h | --help] [-f | --force] [-u | --uptodate]
[-o | --output <dir>] [-p | --permission <perm>] [path ...]
Synchronize Go package and GitHub style README.md documentation by embedding
Go documentation, source code, test and command output directly from the Go
codebase. This ensures that program documentation is kept in one place—the
Go code itself—while keeping the README and package documentation
automatically up to date. It does this by processing template files
containing markdown formatting and replacing embedded directives with
content generated directly from your Go codebase. This ensures your
documentation is always accurate and in sync with the source.
[-v | --verbose ...]
Increase the verbose level for each v provided.
[-d | --directive]
Display directive documentation.
[-l | --license]
Display license before program exits.
[-h | --help]
Display program usage information.
[-f | --force]
Do not confirm overwrite of destination.
[-u | --uptodate]
Returns 0 if no changes would have been made. No writes are
performed.
[-o | --output <dir>]
Direct all output to the specified directory.
[-p | --permission <perm>]
Permissions to use when creating new file.
(can only set RW bits).
[path ...]
Specific template files (named like '.*.gtm.md' or '.*.gtm.go') or a
directory which will be searched for all matching template files.
All subdirectories may be searched by using the special './...'
path. It defaults to search the current directory: '.'
# Directives
The gotomd utility processes template files (`*.gtm.md` and `*.gtm.go`)
into their corresponding `*.md` and `*.go` files, expanding any embedded
directives.
Directives are written inside HTML-style comments:
<!--- gotomd::ACTION::OBJECT [OPTIONAL ...] -->
They may also span multiple lines:
<!--- gotomd::ACTION::OBJECT [OPTIONAL...]
[OPTIONAL ...] -->
<!--- gotomd::ACTION::OBJECT [OPTIONAL...]
[OPTIONAL ...]
...
-->
The `OPTIONAL` elements may be additional objects or parameters, depending on
the `ACTION` being used.
When processing the file, `gotomd` replaces each directive with the generated
content corresponding to that directive.
## Actions
Available actions are:
- `doc` runs and embeds output from `go doc` for a package object
- `dcl` inserts the declaration of package objects
- `dclg` inserts the declaration group for package objects (IE `const` blocks)
- `dcln` inserts the declaration exactly as defined in source including comments
- `dcls` inserts the declaration formatted as a single line
- `irun` runs the package and inserts the output without decorations
- `run` runs the package and frames the output with the command executed
- `snip` includes an external snippet expanding any embedded directives
- `src` includes a Go source file
- `tst` runs a Go test (or all tests) in a package
- `tstc` runs a go test (or all tests) and converts output to TeX to preserve formatting
- `usg` runs the package invoking usage information
### Action: doc
Runs `go doc` on the specified object in the given relative package
directory.
The required argument is the relative package path followed by the name of the
object to document.
A special object name, `package`, includes the package-level comments.
Additional objects may be specified as optional arguments, with or without a
relative directory. If no directory is provided, the most recently specified
directory is used.
<!--- gotomd::doc::./directory/goObject -->
<!--- gotomd::doc::./directory/goObject1 goObject2 -->
<!--- gotomd::doc::./directory/goObject1 goObject2
./differentDirectory/goObject3 goObject4
./anotherDifferentDirectory/package
-->
There are four additional directives all similar to `doc` but focused on object
declaration formatting as follows:
| directive | formatting | comments | typical use |
| --------- | ----------------------- | -------: | ------------------------------- |
| `dcl` | preserves source layout | no | show declaration cleanly |
| `dclg` | exact source layout | yes | show as written in group block |
| `dcln` | exact source layout | yes | show source as written |
| `dcls` | single line | no | compact summaries / inline docs |
See individual Action sections for more detail.
### Action: dcl
Similar to the `doc` directive, `dcl` inserts the declaration of the specified
object as formatted in the source file, excluding comments.
This preserves the original multi-line source layout.
<!--- gotomd::dcl::./directory/goObject
[[./directory/]goObject...]
...
-->
### Action: dclg
Similar to the `doc` directive, `dclg` inserts the grouped declaration group
containing the specified object exactly as formatted in the source files,
including comments.
This is limited to grouped `const (...)` and `var (...)` blocks.
<!--- gotomd::dclg::./directory/goObject
[[./directory/]goObject...]
...
-->
### Action: dcln
Similar to the `doc` directive, `dcln` inserts the declaration exactly as it
appears in the source file, including all associated comments.
This is the closest representation of the original source code.
<!--- gotomd::dcln::./directory/goObject
[[./directory/]goObject...
...
-->
### Action: dcls
Similar to the `doc` directive, `dcls` inserts the declaration of the
specified object reformatted onto a single line.
Comments are not included.
<!--- gotomd::dcls::./directory/goObject
[[./directory/]goObject...
...
-->
### Action: irun
Runs `go run` on the package in the specified directory (assumes `main`) with
the provided arguments.
The output is embedded as preformatted text without decorations.
<!--- gotomd::irun::./directory/. [args ...] -->
### Action: run
Runs `go run` on the package in the specified directory (assumes `main`) with
the provided arguments.
The output is framed together with the command that was executed.
<!--- gotomd::run::./directory/. [args ...] -->
### Action: snip
Loads the referenced snippet and expands any embedded directives.
If the optional first parameter (the word `string`) is present then the output
will be a series of concatenated quote terminated escaped strings suitable of
embedding in code.
If the optional [`startAfter`] argument is supplied, only content appearing
after the first line matching `startAfter` is included.
<!--- gotomd::snip::./directory/fileName [string ][startAfter] -->
### Action: src
Inserts the contents of the specified Go source file, formatted as Go code.
<!--- gotomd::src::./directory/fileName.go -->
### Action: tst
Runs the specified Go test.
A `.` represents all tests.
<!--- gotomd::tst::./directory/testName -->
<!--- gotomd::tst::./directory/. -->
### Action: tstc
Runs the specified Go test.
A `.` represents all tests.
The output is converted to TeX format to preserve text decorations when
displayed on the GitHub website.
<!--- gotomd::tstc::./directory/testName -->
<!--- gotomd::tstc::./directory/. -->
### Action: usg
Runs `go run` flagged to return usage information using the provided arguments
(assumes `main`) formatting the output for .md or .go files respectively.
The output is embedded as preformatted text without decorations.
<!--- gotomd::usg::./directory/. [args ...] -->
# Dedication
***************************************************************************
** **
** This project is dedicated to Reem. **
** Your brilliance, courage, and quiet strength continue to inspire me. **
** Every line is written in gratitude for the light and hope you brought **
** into my life. **
** **
***************************************************************************
NOTE: Documentation reviewed and polished with the assistance of ChatGPT from
OpenAI.
*/
package main