github.com/tetrafolium/tflint@v0.8.0/main.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"log"
     6  	"os"
     7  	"path"
     8  	"runtime"
     9  	"strings"
    10  
    11  	"github.com/hashicorp/logutils"
    12  	colorable "github.com/mattn/go-colorable"
    13  	"github.com/wata727/tflint/cmd"
    14  )
    15  
    16  func main() {
    17  	cli := cmd.NewCLI(colorable.NewColorable(os.Stdout), colorable.NewColorable(os.Stderr))
    18  	filter := &logutils.LevelFilter{
    19  		Levels:   []logutils.LogLevel{"DEBUG", "INFO", "WARN", "ERROR"},
    20  		MinLevel: logutils.LogLevel(strings.ToUpper(os.Getenv("TFLINT_LOG"))),
    21  		Writer:   os.Stderr,
    22  	}
    23  	log.SetOutput(filter)
    24  	log.SetFlags(log.Ltime | log.Lshortfile)
    25  
    26  	defer func() {
    27  		if r := recover(); r != nil {
    28  			fmt.Fprintf(os.Stderr, "Panic: %v\n", r)
    29  			for depth := 0; ; depth++ {
    30  				pc, src, line, ok := runtime.Caller(depth)
    31  				if !ok {
    32  					break
    33  				}
    34  				fmt.Fprintf(os.Stderr, " -> %d: %s: %s(%d)\n", depth, runtime.FuncForPC(pc).Name(), strings.Replace(src, path.Dir(src), "", 1), line)
    35  			}
    36  			fmt.Fprintln(os.Stderr, `
    37  TFLint crashed... :(
    38  Please attach an output log, describe the situation and version that occurred and post an issue to https://github.com/wata727/tflint/issues`)
    39  			os.Exit(cmd.ExitCodeError)
    40  		}
    41  	}()
    42  
    43  	os.Exit(cli.Run(os.Args))
    44  }