d1353e1f7c
* update code.gitea.io/sdk/gitea v0.13.1 -> v0.13.2 * update github.com/go-swagger/go-swagger v0.25.0 -> v0.26.0 * update github.com/google/uuid v1.1.2 -> v1.2.0 * update github.com/klauspost/compress v1.11.3 -> v1.11.7 * update github.com/lib/pq 083382b7e6fc -> v1.9.0 * update github.com/markbates/goth v1.65.0 -> v1.66.1 * update github.com/mattn/go-sqlite3 v1.14.4 -> v1.14.6 * update github.com/mgechev/revive 246eac737dc7 -> v1.0.3 * update github.com/minio/minio-go/v7 v7.0.6 -> v7.0.7 * update github.com/niklasfasching/go-org v1.3.2 -> v1.4.0 * update github.com/olivere/elastic/v7 v7.0.21 -> v7.0.22 * update github.com/pquerna/otp v1.2.0 -> v1.3.0 * update github.com/xanzy/go-gitlab v0.39.0 -> v0.42.0 * update github.com/yuin/goldmark v1.2.1 -> v1.3.1
96 lines
2.7 KiB
Go
Vendored
96 lines
2.7 KiB
Go
Vendored
// Copyright 2018 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package analysisflags
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"sort"
|
|
"strings"
|
|
|
|
"golang.org/x/tools/go/analysis"
|
|
)
|
|
|
|
const help = `PROGNAME is a tool for static analysis of Go programs.
|
|
|
|
PROGNAME examines Go source code and reports suspicious constructs,
|
|
such as Printf calls whose arguments do not align with the format
|
|
string. It uses heuristics that do not guarantee all reports are
|
|
genuine problems, but it can find errors not caught by the compilers.
|
|
`
|
|
|
|
// Help implements the help subcommand for a multichecker or unitchecker
|
|
// style command. The optional args specify the analyzers to describe.
|
|
// Help calls log.Fatal if no such analyzer exists.
|
|
func Help(progname string, analyzers []*analysis.Analyzer, args []string) {
|
|
// No args: show summary of all analyzers.
|
|
if len(args) == 0 {
|
|
fmt.Println(strings.Replace(help, "PROGNAME", progname, -1))
|
|
fmt.Println("Registered analyzers:")
|
|
fmt.Println()
|
|
sort.Slice(analyzers, func(i, j int) bool {
|
|
return analyzers[i].Name < analyzers[j].Name
|
|
})
|
|
for _, a := range analyzers {
|
|
title := strings.Split(a.Doc, "\n\n")[0]
|
|
fmt.Printf(" %-12s %s\n", a.Name, title)
|
|
}
|
|
fmt.Println("\nBy default all analyzers are run.")
|
|
fmt.Println("To select specific analyzers, use the -NAME flag for each one,")
|
|
fmt.Println(" or -NAME=false to run all analyzers not explicitly disabled.")
|
|
|
|
// Show only the core command-line flags.
|
|
fmt.Println("\nCore flags:")
|
|
fmt.Println()
|
|
fs := flag.NewFlagSet("", flag.ExitOnError)
|
|
flag.VisitAll(func(f *flag.Flag) {
|
|
if !strings.Contains(f.Name, ".") {
|
|
fs.Var(f.Value, f.Name, f.Usage)
|
|
}
|
|
})
|
|
fs.SetOutput(os.Stdout)
|
|
fs.PrintDefaults()
|
|
|
|
fmt.Printf("\nTo see details and flags of a specific analyzer, run '%s help name'.\n", progname)
|
|
|
|
return
|
|
}
|
|
|
|
// Show help on specific analyzer(s).
|
|
outer:
|
|
for _, arg := range args {
|
|
for _, a := range analyzers {
|
|
if a.Name == arg {
|
|
paras := strings.Split(a.Doc, "\n\n")
|
|
title := paras[0]
|
|
fmt.Printf("%s: %s\n", a.Name, title)
|
|
|
|
// Show only the flags relating to this analysis,
|
|
// properly prefixed.
|
|
first := true
|
|
fs := flag.NewFlagSet(a.Name, flag.ExitOnError)
|
|
a.Flags.VisitAll(func(f *flag.Flag) {
|
|
if first {
|
|
first = false
|
|
fmt.Println("\nAnalyzer flags:")
|
|
fmt.Println()
|
|
}
|
|
fs.Var(f.Value, a.Name+"."+f.Name, f.Usage)
|
|
})
|
|
fs.SetOutput(os.Stdout)
|
|
fs.PrintDefaults()
|
|
|
|
if len(paras) > 1 {
|
|
fmt.Printf("\n%s\n", strings.Join(paras[1:], "\n\n"))
|
|
}
|
|
|
|
continue outer
|
|
}
|
|
}
|
|
log.Fatalf("Analyzer %q not registered", arg)
|
|
}
|
|
}
|