示例#1
0
文件: cfg.go 项目: ivandejanovic/mlpl
func getLocaleFromConfig(configFile string) {
	config, err := ioutil.ReadFile(configFile)
	if err != nil {
		panic(err)
	}

	json.Unmarshal(config, locale.Locale)
	locale.AssembleReserved()
}
示例#2
0
文件: cfg.go 项目: ivandejanovic/mlpl
func HandleArgs() (bool, string) {
	var abort bool = true
	var codeFile string

	args := os.Args[1:]
	argc := len(args)

	for index := 0; index < argc; index++ {
		var flag string = empty
		var flagArg string = args[index]

		if strings.HasPrefix(flagArg, doubleMinus) {
			flag = strings.TrimPrefix(flagArg, doubleMinus)
		} else if strings.HasPrefix(flagArg, minus) {
			flag = strings.TrimPrefix(flagArg, minus)
		}

		if flag != empty {
			switch flag {
			case "h", "help":
				fmt.Println()
				fmt.Println(usage)
				fmt.Println()
				fmt.Println("Options:")
				fmt.Println("  -h, --help       Prints help")
				fmt.Println("  -v, --version    Prints version")
			case "v", "version":
				fmt.Println("MLPL interpreter version 1.0.0")
			default:
				fmt.Println("Invalid usage. For correct usage examples please try: mlpl -h")
			}
			return abort, codeFile
		}
	}

	if argc < 1 || argc > 2 {
		fmt.Println(usage)
		return abort, codeFile
	}

	if argc == 2 {
		getLocaleFromConfig(args[1])
	} else {
		locale.AssembleReserved()
	}

	//If we get this far we have good data to process
	abort = false
	codeFile = args[0]

	return abort, codeFile
}