Skip to content

Commit

Permalink
docs: move godoc helper to dedicated package
Browse files Browse the repository at this point in the history
Signed-off-by: Hank Donnay <[email protected]>
  • Loading branch information
hdonnay committed Sep 21, 2023
1 parent 8065729 commit af96adb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 26 deletions.
2 changes: 1 addition & 1 deletion book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ create-missing = true
git-repository-url= "https://github.com/quay/claircore"

[preprocessor.godoc]
command = "go run docs/godoc.go"
command = "go run github.com/quay/claircore/internal/cmd/mdbook-godoc"

[preprocessor.make_target]
command = "go run docs/make_target.go"
Expand Down
32 changes: 7 additions & 25 deletions docs/godoc.go → internal/cmd/mdbook-godoc/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
//go:build ignore

// Godoc is a helper meant to inline `go doc` output.
// Mdbook-godoc is a helper meant to inline `go doc` output.
//
// Any preprocessor directive like
//
Expand All @@ -15,33 +13,23 @@ package main
import (
"bytes"
"context"
"encoding/json"
"fmt"
"log"
"os"
"os/exec"
"os/signal"
"regexp"
"strings"
"sync"

"github.com/quay/claircore/internal/mdbook"
)

func main() {
log.SetFlags(log.LstdFlags | log.Lmsgprefix)
log.SetPrefix("godoc: ")
mdbook.Args(os.Args)
var marker = regexp.MustCompile(`\{\{#\s*godoc\s(.+)\}\}`)

cfg, book, err := mdbook.Decode(os.Stdin)
if err != nil {
panic(err)
}
marker := regexp.MustCompile(`\{\{#\s*godoc\s(.+)\}\}`)
ctx := context.Background()
ctx, cancel := signal.NotifyContext(ctx, os.Interrupt, os.Kill)
defer cancel()
func main() {
mdbook.Main("godoc", newProc)
}

func newProc(ctx context.Context, cfg *mdbook.Context) (*mdbook.Proc, error) {
proc := mdbook.Proc{
Chapter: func(ctx context.Context, b *strings.Builder, c *mdbook.Chapter) error {
if c.Path == nil {
Expand Down Expand Up @@ -75,11 +63,5 @@ func main() {
return ret
},
}
if err := proc.Walk(ctx, book); err != nil {
panic(err)
}

if err := json.NewEncoder(os.Stdout).Encode(&book); err != nil {
panic(err)
}
return &proc, nil
}

0 comments on commit af96adb

Please sign in to comment.