github.com/pankona/gometalinter@v2.0.11+incompatible/_linters/src/4d63.com/gochecknoglobals/main.go (about)

     1  package main // import "4d63.com/gochecknoglobals"
     2  
     3  import (
     4  	"flag"
     5  	"fmt"
     6  	"os"
     7  )
     8  
     9  func main() {
    10  	flagPrintHelp := flag.Bool("h", false, "Print help")
    11  	flagIncludeTests := flag.Bool("t", false, "Include tests")
    12  	flag.Usage = func() {
    13  		fmt.Fprintf(os.Stderr, "Usage: gochecknoglobals [-t] [path] [path] ...\n")
    14  		flag.PrintDefaults()
    15  	}
    16  	flag.Parse()
    17  
    18  	if *flagPrintHelp {
    19  		flag.Usage()
    20  		return
    21  	}
    22  
    23  	includeTests := *flagIncludeTests
    24  
    25  	paths := flag.Args()
    26  	if len(paths) == 0 {
    27  		paths = []string{"./..."}
    28  	}
    29  
    30  	exitWithError := false
    31  
    32  	for _, path := range paths {
    33  		messages, err := checkNoGlobals(path, includeTests)
    34  		for _, message := range messages {
    35  			fmt.Fprintf(os.Stdout, "%s\n", message)
    36  			exitWithError = true
    37  		}
    38  		if err != nil {
    39  			fmt.Fprintf(os.Stderr, "error: %s\n", err)
    40  			exitWithError = true
    41  		}
    42  	}
    43  
    44  	if exitWithError {
    45  		os.Exit(1)
    46  	}
    47  }