func printError(message string) { if arg.GetB(ARG_DAEMON) { fmt.Printf("\n%s\n\n", message) } else { fmtc.Printf("\n{r}%s{!}\n\n", message) } }
func Init() { runtime.GOMAXPROCS(1) args, errs := arg.Parse(argMap) if len(errs) != 0 { printError("Errors while argument parsing:") for _, err := range errs { printError(" %v", err) } os.Exit(1) } if arg.GetB(ARG_NO_COLOR) { fmtc.DisableColors = true } if arg.GetB(ARG_VER) { showAbout() return } if len(args) == 0 || arg.GetB(ARG_HELP) { showUsage() return } file := findFile(args[0]) for { if fsutil.CheckPerms("FRS", file) { break } time.Sleep(time.Millisecond * 500) } if arg.Has(ARG_DATE_FROM) || arg.Has(ARG_DATE_TO) { filterFile(file) } else { readFile(file) } }
func setupLog() { var err error if arg.GetB(ARG_DAEMON) { err = log.Set(knf.GetS(LOG_FILE), knf.GetM(LOG_PERMS, 0644)) if err != nil { fmt.Printf("Can't setup logger: %v\n", err) os.Exit(1) } } err = log.MinLevel(knf.GetS(LOG_LEVEL, "info")) if err != nil { fmt.Printf("Can't set log level: %v\n", err) } }
func Init() { var err error var errs []error runtime.GOMAXPROCS(1) if len(os.Args) <= 1 { showUsage() return } args, errs := arg.Parse(argMap) if len(errs) != 0 { for _, err := range errs { fmt.Println(err.Error()) } os.Exit(1) } if arg.GetB(ARG_NO_COLOR) { fmtc.DisableColors = true } if arg.GetB(ARG_VER) { showAbout() return } if len(args) == 0 || arg.GetB(ARG_HELP) { showUsage() return } // Slice with valid config paths confPaths := []string{ arg.GetS(ARG_CONFIG), "/etc/mockka.conf", "~/mockka.conf", "mockka.conf", } err = knf.Global(fsutil.ProperPath("FRS", confPaths)) if err != nil { fmt.Println(err.Error()) os.Exit(1) } errs = validateConfig() if len(errs) != 0 { for _, err := range errs { fmt.Println(err.Error()) } os.Exit(1) } setupLog() if arg.GetB(ARG_DAEMON) { registerSignalHandlers() } execCommand(args) }