diff --git a/cmd/mccl/main.go b/cmd/mccl/main.go index c5dbcd7..729d601 100755 --- a/cmd/mccl/main.go +++ b/cmd/mccl/main.go @@ -131,101 +131,49 @@ func parseArguments(args []string) (parsed arguments, err error) { parsed.Username = "Anonymous" parsed.Directory = "." parsed.Uuid = "00000000-0000-0000-0000-000000000000" + for i := 0; i < len(args); i++ { - if len(args[i]) > 2 && args[i][0] == '-' && args[i][1] == '-' { - switch args[i][2:] { - case "version": - parsed.ShowVersion = true - case "help": - parsed.ShowHelp = true - case "demand-press-enter": - parsed.DemandPressEnter = true - case "username": - if len(args) == i+1 || args[i+1][0] == '-' { - err = errNoOptArg{ArgName: args[i]} - return - } - parsed.Username = args[i+1] - i++ - case "uuid": - if len(args) == i+1 || args[i+1][0] == '-' { - err = errNoOptArg{ArgName: args[i]} - return - } - parsed.Uuid = args[i+1] - i++ - case "java-Xmx": - if len(args) == i+1 || args[i+1][0] == '-' { - err = errNoOptArg{ArgName: args[i]} - return - } - parsed.JavaXmx = args[i+1] - i++ - case "profile": - parsed.UseProfile = true - default: - err = fmt.Errorf("an unknown option %s was provided", args[i]) + switch args[i] { + case "-v": + fallthrough + case "--version": + parsed.ShowVersion = true + case "-h": + fallthrough + case "--help": + parsed.ShowHelp = true + case "--demand-press-enter": + parsed.DemandPressEnter = true + case "-u": + fallthrough + case "--username": + if len(args) == i+1 || args[i+1][0] == '-' { + err = errNoOptArg{ArgName: args[i]} return } - } else if args[i][0] == '-' && len(args[i]) > 1 { - for _, option := range args[i][1:] { - switch option { - case 'v': - parsed.ShowVersion = true - case 'h': - parsed.ShowHelp = true - case 'u': - if len(args) == i+1 || args[i+1][0] == '-' { - err = errNoOptArg{ArgName: args[i]} - return - } - parsed.Username = args[i+1] - i++ - case 'U': - if len(args) == i+1 || args[i+1][0] == '-' { - err = errNoOptArg{ArgName: args[i]} - return - } - parsed.Uuid = args[i+1] - i++ - default: - err = fmt.Errorf("an unknown option %c was provided", option) - return - } - } - } else { - if parsed.Command != "" { - err = fmt.Errorf("only one command should present") + parsed.Username = args[i+1] + i++ + case "-U": + fallthrough + case "--uuid": + if len(args) == i+1 || args[i+1][0] == '-' { + err = errNoOptArg{ArgName: args[i]} return } - switch parsed.Command = args[i]; parsed.Command { - case "i": - fallthrough - case "install": - fallthrough - case "r": - fallthrough - case "run": - if len(args) <= i+3 || args[i+1][0] == '-' || args[i+2][0] == '-' { - err = fmt.Errorf("not enough arguments was provided") - return - } - parsed.GameVersion = args[i+1] - parsed.Directory = args[i+2] - i += 2 - case "l": - fallthrough - case "list": - if len(args) <= i+2 || args[i+1][0] == '-' { - err = fmt.Errorf("not enough arguments was provided") - return - } - parsed.Directory = args[i+1] - i++ - default: - err = fmt.Errorf("an unknown command %s was provided", parsed.Command) + parsed.Uuid = args[i+1] + i++ + case "--java-Xmx": + if len(args) == i+1 || args[i+1][0] == '-' { + err = errNoOptArg{ArgName: args[i]} return } + parsed.JavaXmx = args[i+1] + i++ + case "--profile": + parsed.UseProfile = true + default: + err = fmt.Errorf("an unknown option %s was provided", args[i]) + return } } return