Skip to content

Commit 7d4ab95

Browse files
committed
add some flags
1 parent d02bc8c commit 7d4ab95

File tree

5 files changed

+69
-35
lines changed

5 files changed

+69
-35
lines changed

content/docs/reference/microcontrollers/esp32-coreboard-v2.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: "Espressif ESP32 Core Board V2"
2+
title: "ESP32 Core Board V2"
33
weight: 3
44
---
55

doc-gen/Makefile

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,14 @@
11
all:
2-
go run . `tinygo targets`
2+
go run . --machine --interfaces --pins --matrix `tinygo targets`
3+
4+
interfaces:
5+
go run . --interfaces `tinygo targets`
6+
7+
pins:
8+
go run . --pins `tinygo targets`
9+
10+
matrix:
11+
go run . --matrix `tinygo targets`
12+
13+
help:
14+
go run . --help

doc-gen/cmd/root.go

+28-20
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ var targetsKnownToSkip = map[string]struct{}{"atmega1284p": {}, "attiny1616": {}
4545
var targetsKnownToSkipAndShouldBeDocumented = map[string]struct{}{"bluemicro840": {}, "esp32-c3-devkit-rust-1": {},
4646
"feather-m0-express": {}}
4747

48-
// TODO: fix wrong matrix output
4948
// TODO: revert unneeded adjustments in mcu pages (e.g. link text)
50-
func Execute(targets []string) {
49+
// TODO: support parameters: machine doc, pins table, interfaces table, hw matrix
50+
func Execute(targets []string, createMachineDoc, updateBoardInterfaces, updateBoardPins, createHardwareMatrix bool) {
5151
// collect
5252
collector := collectFiles(targets)
5353

@@ -62,21 +62,24 @@ func Execute(targets []string) {
6262
if co.docStatus == canProcessed {
6363
fmt.Println(" Generating documentation...")
6464
machineDocPath := filepath.Join(controllerDocBaseDir, "machine", target+".md")
65-
if err := updateMicrocontrollerDocumentation(target, machineDocPath, co.controllerDocPath); err != nil {
65+
if err := updateMicrocontrollerDocumentation(target, machineDocPath, co.controllerDocPath,
66+
createMachineDoc, updateBoardInterfaces, updateBoardPins); err != nil {
6667
fmt.Fprintln(os.Stderr, " skipping: because error\t\t", err)
6768
co.errors = append(co.errors, err)
6869
}
6970
}
7071

71-
fmt.Println(" Prepare hardware matrix...")
72-
matrixRow, err := hardwarematrix.ParseFeatureMap(co.controllerDocPath)
73-
if err != nil {
74-
fmt.Fprintln(os.Stderr, " skipping: because error\t\t", err)
75-
co.errors = append(co.errors, err)
76-
continue
77-
}
72+
if createHardwareMatrix {
73+
fmt.Println(" Prepare hardware matrix...")
74+
matrixRow, err := hardwarematrix.ParseFeatureMap(co.controllerDocPath)
75+
if err != nil {
76+
fmt.Fprintln(os.Stderr, " skipping: because error\t\t", err)
77+
co.errors = append(co.errors, err)
78+
continue
79+
}
7880

79-
co.matrixRow = matrixRow
81+
co.matrixRow = matrixRow
82+
}
8083

8184
if co.docStatus == documentFound {
8285
co.docStatus = finishedWithoutTargetOk
@@ -85,10 +88,12 @@ func Execute(targets []string) {
8588
co.docStatus = finishedOk
8689
}
8790

88-
fmt.Println("\nUpdate hardware matrix...")
89-
hwmatrixDocPath := filepath.Join("..", "content", "docs", "reference", "hardware-matrix.md")
90-
if err := updateHardwareMatrix(hwmatrixDocPath, collector); err != nil {
91-
fmt.Fprintln(os.Stderr, " skipping: because error\t\t", err)
91+
if createHardwareMatrix {
92+
fmt.Println("\nUpdate hardware matrix...")
93+
hwmatrixDocPath := filepath.Join("..", "content", "docs", "reference", "hardware-matrix.md")
94+
if err := updateHardwareMatrix(hwmatrixDocPath, collector); err != nil {
95+
fmt.Fprintln(os.Stderr, " skipping: because error\t\t", err)
96+
}
9297
}
9398

9499
// summary
@@ -201,18 +206,21 @@ func collectFiles(targets []string) map[string]*collection {
201206
return collector
202207
}
203208

204-
func updateMicrocontrollerDocumentation(target, machineDocPath, controllerDocPath string) error {
209+
func updateMicrocontrollerDocumentation(target, machineDocPath, controllerDocPath string,
210+
createMachineDoc, updateBoardInterfaces, updateBoardPins bool) error {
205211
ti, err := targetinfo.Create(target)
206212
if err != nil {
207213
return fmt.Errorf("target info can not be created: %v", err)
208214
}
209215

210-
err = machinepackagedoc.CreateNew(machineDocPath, target, ti.Pkg)
211-
if err != nil {
212-
return fmt.Errorf("error on write machine package doc: %v", err)
216+
if createMachineDoc {
217+
err = machinepackagedoc.CreateNew(machineDocPath, target, ti.Pkg)
218+
if err != nil {
219+
return fmt.Errorf("error on write machine package doc: %v", err)
220+
}
213221
}
214222

215-
errors := boarddoc.Update(controllerDocPath, ti)
223+
errors := boarddoc.Update(controllerDocPath, ti, updateBoardInterfaces, updateBoardPins)
216224
if len(errors) > 0 {
217225
return fmt.Errorf("error on update board documentation: %v", errors)
218226
}

doc-gen/doc-gen.go

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
package main
22

33
import (
4-
"os"
4+
"flag"
5+
"fmt"
56

67
"github.com/tinygo-org/tinygo-site/doc-gen/cmd"
78
)
89

910
// main just calls the Execute function
1011
func main() {
12+
13+
createMachineDoc := flag.Bool("machine", false, "re-create machine package documentation for the given targets")
14+
updateBoardInterfaces := flag.Bool("interfaces", false, "update the Interfaces table for the given targets")
15+
updateBoardPins := flag.Bool("pins", false, "update the Pins table for the given targets")
16+
createHardwareMatrix := flag.Bool("matrix", false, "re-create the hardware matrix document")
17+
flag.Parse()
18+
1119
// get the targets from the list of command line options
12-
targets := os.Args[1:]
13-
cmd.Execute(targets)
20+
targets := flag.Args()
21+
fmt.Printf("Targets: %+q\n", targets)
22+
23+
cmd.Execute(targets, *createMachineDoc, *updateBoardInterfaces, *updateBoardPins, *createHardwareMatrix)
1424
}

doc-gen/internal/boarddoc/boarddoc.go

+14-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/tinygo-org/tinygo-site/doc-gen/internal/targetinfo"
99
)
1010

11-
func Update(path string, ti *targetinfo.TargetInfo) []error {
11+
func Update(path string, ti *targetinfo.TargetInfo, updateInterfaces, updatePins bool) []error {
1212
// Read the entire Markdown file in memory.
1313
docBuf, err := os.ReadFile(path)
1414
if err != nil {
@@ -18,17 +18,21 @@ func Update(path string, ti *targetinfo.TargetInfo) []error {
1818

1919
var interfacesUpdated, pinsUpdated bool
2020
var errors []error
21-
features := ti.SupportedFeatures()
22-
doc, interfacesUpdated, err = updateInterfacesSection(doc, features)
23-
if err != nil {
24-
fmt.Fprintln(os.Stderr, "interfaces section could not be updated", err)
25-
errors = append(errors, err)
21+
if updateInterfaces {
22+
features := ti.SupportedFeatures()
23+
doc, interfacesUpdated, err = updateInterfacesSection(doc, features)
24+
if err != nil {
25+
fmt.Fprintln(os.Stderr, "interfaces section could not be updated", err)
26+
errors = append(errors, err)
27+
}
2628
}
2729

28-
doc, pinsUpdated, err = updatePinsSection(doc, ti)
29-
if err != nil {
30-
fmt.Fprintln(os.Stderr, "pins section could not be updated", err)
31-
errors = append(errors, err)
30+
if updatePins {
31+
doc, pinsUpdated, err = updatePinsSection(doc, ti)
32+
if err != nil {
33+
fmt.Fprintln(os.Stderr, "pins section could not be updated", err)
34+
errors = append(errors, err)
35+
}
3236
}
3337

3438
if !interfacesUpdated && !pinsUpdated {

0 commit comments

Comments
 (0)