-
Notifications
You must be signed in to change notification settings - Fork 7
/
check.go
41 lines (37 loc) · 950 Bytes
/
check.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"context"
"flag"
"fmt"
)
func init() {
flagSet := flag.NewFlagSet("check", flag.ExitOnError)
var (
contentVersion = flagSet.String("content-version", "", "version of content to check")
)
handler := func(args []string) error {
flagSet.Parse(args)
site, _, err := siteFromFlags()
if err != nil {
return err
}
problems, err := site.Check(context.Background(), *contentVersion)
if err != nil {
return err
}
if len(problems) > 0 {
for _, problem := range problems {
fmt.Println(problem)
}
return fmt.Errorf("%d problems found", len(problems))
}
return nil
}
// Register the command.
commands = append(commands, &command{
FlagSet: flagSet,
ShortDescription: "check all source files for problems",
LongDescription: "The check subcommand checks all source files for problems, such as template execution errors and broken links.",
handler: handler,
})
}