Skip to content

Commit

Permalink
docs: move make_target 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 7ee4292 commit c5ea100
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 24 deletions.
2 changes: 1 addition & 1 deletion book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ git-repository-url= "https://github.com/quay/claircore"
command = "go run github.com/quay/claircore/internal/cmd/mdbook-godoc"

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

[preprocessor.injecturls]
command = "go run github.com/quay/claircore/internal/cmd/mdbook-injecturls"
28 changes: 5 additions & 23 deletions docs/make_target.go → internal/cmd/mdbook-make_target/main.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
//go:build ignore

// Make_target is a helper to check that documented Makefile targets exist.
// Mdbook-make_target is a helper to check that documented Makefile targets exist.
package main

import (
"bytes"
"context"
"encoding/json"
"fmt"
"log"
"os"
"os/exec"
"os/signal"
"path/filepath"
"regexp"
"strings"
Expand Down Expand Up @@ -41,18 +37,10 @@ func readMakefile(ctx context.Context) {
var marker = regexp.MustCompile(`\{\{#\s*make_target\s(.+)\}\}`)

func main() {
log.SetFlags(log.LstdFlags | log.Lmsgprefix)
log.SetPrefix("make_target: ")
mdbook.Args(os.Args)

_, book, err := mdbook.Decode(os.Stdin)
if err != nil {
panic(err)
}
ctx := context.Background()
ctx, cancel := signal.NotifyContext(ctx, os.Interrupt, os.Kill)
defer cancel()
mdbook.Main("make_target", newProc)
}

func newProc(_ context.Context, _ *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 @@ -81,11 +69,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 c5ea100

Please sign in to comment.