diff --git a/book.toml b/book.toml index b334e2d04..596c92f29 100644 --- a/book.toml +++ b/book.toml @@ -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" diff --git a/docs/godoc.go b/internal/cmd/mdbook-godoc/main.go similarity index 69% rename from docs/godoc.go rename to internal/cmd/mdbook-godoc/main.go index cfd8376bf..957f25898 100644 --- a/docs/godoc.go +++ b/internal/cmd/mdbook-godoc/main.go @@ -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 // @@ -15,12 +13,9 @@ package main import ( "bytes" "context" - "encoding/json" "fmt" "log" - "os" "os/exec" - "os/signal" "regexp" "strings" "sync" @@ -28,20 +23,13 @@ import ( "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 { @@ -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 }