1 // Copyright 2018 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // Package multichecker defines the main function for an analysis driver
6 // with several analyzers. This package makes it easy for anyone to build
7 // an analysis tool containing just the analyzers they need.
18 "golang.org/x/tools/go/analysis"
19 "golang.org/x/tools/go/analysis/internal/analysisflags"
20 "golang.org/x/tools/go/analysis/internal/checker"
21 "golang.org/x/tools/go/analysis/unitchecker"
24 func Main(analyzers ...*analysis.Analyzer) {
25 progname := filepath.Base(os.Args[0])
27 log.SetPrefix(progname + ": ") // e.g. "vet: "
29 if err := analysis.Validate(analyzers); err != nil {
33 checker.RegisterFlags()
35 analyzers = analysisflags.Parse(analyzers, true)
39 fmt.Fprintf(os.Stderr, `%[1]s is a tool for static analysis of Go programs.
41 Usage: %[1]s [-flag] [package]
43 Run '%[1]s help' for more detail,
44 or '%[1]s help name' for details and flags of a specific analyzer.
49 if args[0] == "help" {
50 analysisflags.Help(progname, analyzers, args[1:])
54 if len(args) == 1 && strings.HasSuffix(args[0], ".cfg") {
55 unitchecker.Run(args[0], analyzers)
59 os.Exit(checker.Run(args, analyzers))