Skip to content

Commit db4c87b

Browse files
committed
test(docs): generate and verify help-all output
1 parent b29d0e8 commit db4c87b

File tree

6 files changed

+781
-663
lines changed

6 files changed

+781
-663
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ This simplified [diagram](https://github.com/jgraph/drawio) shows how Trice work
110110
- [Trice User Manual](./docs/TriceUserManual.md) (includes updated information from the interrupt blog)
111111
- Check [issues](https://github.com/rokath/trice/issues) and [discussions](https://github.com/rokath/trice/discussions), including closed items
112112
- Read the target source code, especially [triceDefaultConfig.h](./src/triceDefaultConfig.h)
113-
- View [CLI](https://en.wikipedia.org/wiki/Command-line_interface) options by running `trice help -all` in a terminal or reading [tricehelpall_test.go](./internal/args/tricehelpall_test.go)
113+
- View [CLI](https://en.wikipedia.org/wiki/Command-line_interface) options by running `trice help -all` in a terminal or reading the generated file [trice-help-all.txt](./docs/ref/trice-help-all.txt)
114+
- Refresh the checked-in CLI help documentation with `go generate ./internal/args`
114115
- Look at and modify [./internal/emitter/lineTransformerANSI.go](./internal/emitter/lineTransformerANSI.go) if needed (requires running `go install ./cmd/trice/...` afterwards)
115116

116117
## Debugging with VS-Code and Clang

cmd/generate-helpall-doc/main.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"path/filepath"
7+
8+
"github.com/rokath/trice/internal/args"
9+
)
10+
11+
const outputFile = "docs/ref/trice-help-all.txt"
12+
13+
func main() {
14+
text, err := args.RenderHelpText("-all")
15+
if err != nil {
16+
fail("render help text", err)
17+
}
18+
19+
root, err := repoRoot()
20+
if err != nil {
21+
fail("locate repository root", err)
22+
}
23+
targetFile := filepath.Join(root, outputFile)
24+
25+
if err := os.MkdirAll(filepath.Dir(targetFile), 0o755); err != nil {
26+
fail("create output directory", err)
27+
}
28+
if err := os.WriteFile(targetFile, []byte(text), 0o644); err != nil {
29+
fail("write help output", err)
30+
}
31+
}
32+
33+
func repoRoot() (string, error) {
34+
wd, err := os.Getwd()
35+
if err != nil {
36+
return "", err
37+
}
38+
// go generate runs in the package directory of the file containing the directive.
39+
// The directive lives in internal/args, so the repository root is two levels up.
40+
return filepath.Clean(filepath.Join(wd, "..", "..")), nil
41+
}
42+
43+
func fail(step string, err error) {
44+
fmt.Fprintf(os.Stderr, "%s: %v\n", step, err)
45+
os.Exit(1)
46+
}

0 commit comments

Comments
 (0)