예제 #1
0
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)
	}
}
예제 #2
0
파일: cli.go 프로젝트: essentialkaos/mockka
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)
}