Skip to content

Commit

Permalink
add -quiet flag to update-checks-doc script
Browse files Browse the repository at this point in the history
and run the script in `make lint`
  • Loading branch information
rhysd committed Oct 24, 2024
1 parent 7691a9a commit d63a8e1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ jobs:
echo "$diffs" >&2
exit 1
fi
- name: Check `docs/checks.md` is up-to-date
run: go run ./scripts/update-checks-doc -check ./docs/checks.md
- name: Install staticcheck
run: |
go install honnef.co/go/tools/cmd/staticcheck@latest
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ t test: .testtimestamp
.staticchecktimestamp: $(TESTS) $(SRCS) $(TOOL)
staticcheck ./...
GOOS=js GOARCH=wasm staticcheck ./playground
go run ./scripts/update-checks-doc -check -quiet ./docs/checks.md
touch .staticchecktimestamp

l lint: .staticchecktimestamp
Expand Down
7 changes: 7 additions & 0 deletions scripts/update-checks-doc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,13 +317,16 @@ var stderr io.Writer = os.Stderr

func Main(args []string) error {
var check bool
var quiet bool
flags := flag.NewFlagSet(args[0], flag.ContinueOnError)
flags.BoolVar(&check, "check", false, "check the document is up-to-date")
flags.BoolVar(&quiet, "quiet", false, "disable trace logs")
flags.SetOutput(stderr)
flags.Usage = func() {
fmt.Fprintln(stderr, "Usage: update-checks-doc [FLAGS] FILE\n\nFlags:")
flags.PrintDefaults()
}

if err := flags.Parse(args[1:]); err != nil {
if err == flag.ErrHelp {
return nil
Expand All @@ -335,6 +338,10 @@ func Main(args []string) error {
}
path := flags.Arg(0)

if quiet {
log.SetOutput(io.Discard)
}

in, err := os.ReadFile(path)
if err != nil {
return fmt.Errorf("could not read the document file: %w", err)
Expand Down
10 changes: 10 additions & 0 deletions scripts/update-checks-doc/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ func TestMainCheckOK(t *testing.T) {
}
}

func TestMainCheckQuietOK(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("update-checks-doc doesn't support Windows")
}
path := filepath.FromSlash("testdata/ok/minimal.out")
if err := Main([]string{"exe", "-check", "-quiet", path}); err != nil {
t.Fatal(err)
}
}

func TestMainPrintHelp(t *testing.T) {
if err := Main([]string{"exe", "-help"}); err != nil {
t.Fatal(err)
Expand Down

0 comments on commit d63a8e1

Please sign in to comment.