Esempio n. 1
0
// findFile try to find log file
func findFile(file string) string {
	if fsutil.IsExist(file) {
		return file
	}

	configPath := fsutil.ProperPath("FRS", confPaths)

	if configPath == "" {
		return file
	}

	config, err := knf.Read(configPath)
	logDir := config.GetS("data:log-dir")

	if err != nil || logDir == "" {
		return file
	}

	if !strings.Contains(file, ".log") {
		file += ".log"
	}

	if fsutil.CheckPerms("FRS", path.Join(logDir, file)) {
		return path.Join(logDir, file)
	}

	return file
}
Esempio n. 2
0
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)
}