Skip to content

Commit

Permalink
tools/govalidate: start of a frontend for tools/internal/parser
Browse files Browse the repository at this point in the history
Parses the given file and reports parsing and validation errors.
  • Loading branch information
danderson committed May 30, 2024
1 parent e8df7ab commit bd4b970
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tools/govalidate/govalidate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package main

import (
"flag"
"fmt"
"os"

"github.com/publicsuffix/list/tools/internal/parser"
)

func main() {
warnings := flag.Bool("with-warnings", false, "also print errors that were downgraded to warnings")
flag.Usage = func() {
fmt.Fprintf(flag.CommandLine.Output(), "Usage: %s [flags] pslfile\n", os.Args[0])
flag.PrintDefaults()
}
flag.Parse()

if flag.NArg() != 1 {
flag.Usage()
}

file := flag.Arg(0)

bs, err := os.ReadFile(file)
if err != nil {
fmt.Fprintf(os.Stderr, "Reading PSL file: %v", err)
os.Exit(1)
}

psl := parser.Parse(string(bs))

for _, err := range psl.Errors {
fmt.Println(err)
}
if *warnings {
for _, err := range psl.Warnings {
fmt.Println(err, "(ignored)")
}
}
if len(psl.Errors) > 0 {
os.Exit(1)
} else {
fmt.Printf("%q seems to be a valid PSL file.\n", file)
}
}

0 comments on commit bd4b970

Please sign in to comment.