Ejemplo n.º 1
0
Archivo: main.go Proyecto: xingskycn/go
func main() {
	Log.SetHandler(log15.StderrHandler)
	stderr, err := term.MaskOut(os.Stderr, term.GetTTYEncoding())
	if err != nil {
		Log.Crit("mask stderr", "encoding", term.GetTTYEncoding(), "error", err)
		os.Exit(1)
	}
	loghlp.UseWriter(stderr)
	Log.SetHandler(log15.StderrHandler)

	flag.Parse()
	if err := lvdump.Dump(flag.Arg(0)); err != nil {
		Log.Error("Dump", "src", flag.Arg(0), "error")
	}
}
Ejemplo n.º 2
0
func main() {
	flagGen := flag.Bool("gen", false, "generate, not check")
	flagVerbose := flag.Bool("v", false, "verbose log")
	flagDiffThreshold := flag.Int("threshold", 10, "difference threshold percent")

	flag.Parse()
	lvl := log15.LvlInfo
	if *flagVerbose {
		lvl = log15.LvlDebug
	}
	Log.SetHandler(
		log15.LvlFilterHandler(lvl,
			log15.StreamHandler(text.NewWriter(os.Stderr, term.GetTTYEncoding()),
				log15.TerminalFormat())),
	)
	wd, err := os.Getwd()
	if err != nil {
		Log.Crit("get wd", "error", err)
		os.Exit(1)
	}
	parentDir = filepath.Dir(wd)
	cmd := exec.Command("go", "build")
	cmd.Dir = parentDir
	Log.Info("building " + parentDir)
	if err := cmd.Run(); err != nil {
		Log.Crit("compiling", "error", err)
		os.Exit(1)
	}
	names := flag.Args()
	if len(names) == 0 {
		dh, err := os.Open("testdata")
		if err != nil {
			Log.Crit("open testdata", "error", err)
			os.Exit(2)
		}

		names, err = dh.Readdirnames(-1)
		_ = dh.Close()
		if err != nil {
			Log.Crit("cannot list", "dir", dh.Name(), "error", err)
			os.Exit(2)
		}
		for i, fn := range names {
			names[i] = filepath.Join(dh.Name(), fn)
		}
	}
	diffThreshold := *flagDiffThreshold
	if diffThreshold > 100 || diffThreshold < 0 {
		diffThreshold = 10
	}
	errCnt := 0
	for _, fn := range names {
		if !strings.HasSuffix(fn, ".eml.gz") && !strings.HasSuffix(fn, ".eml") {
			continue
		}
		if *flagGen {
			if err := genOne(fn); err != nil {
				errCnt++
				Log.Error("gen", "file", fn, "error", err)
			}
		} else if err := checkOne(fn, diffThreshold); err != nil {
			errCnt++
			Log.Error("run", "file", fn, "error", err)
		}
	}
	if errCnt > 0 {
		os.Exit(3)
	}
}