Back then I forgot it is not C, just compare with full strings in switch.

This commit is contained in:
Alexander Andreev 2023-12-09 19:05:47 +04:00
parent 7cb5d35e6a
commit ed493b012a
Signed by: Arav
GPG Key ID: D22A817D95815393

View File

@ -131,102 +131,50 @@ func parseArguments(args []string) (parsed arguments, err error) {
parsed.Username = "Anonymous" parsed.Username = "Anonymous"
parsed.Directory = "." parsed.Directory = "."
parsed.Uuid = "00000000-0000-0000-0000-000000000000" parsed.Uuid = "00000000-0000-0000-0000-000000000000"
for i := 0; i < len(args); i++ { for i := 0; i < len(args); i++ {
if len(args[i]) > 2 && args[i][0] == '-' && args[i][1] == '-' { switch args[i] {
switch args[i][2:] { case "-v":
case "version": fallthrough
case "--version":
parsed.ShowVersion = true parsed.ShowVersion = true
case "help": case "-h":
fallthrough
case "--help":
parsed.ShowHelp = true parsed.ShowHelp = true
case "demand-press-enter": case "--demand-press-enter":
parsed.DemandPressEnter = true parsed.DemandPressEnter = true
case "username": case "-u":
fallthrough
case "--username":
if len(args) == i+1 || args[i+1][0] == '-' { if len(args) == i+1 || args[i+1][0] == '-' {
err = errNoOptArg{ArgName: args[i]} err = errNoOptArg{ArgName: args[i]}
return return
} }
parsed.Username = args[i+1] parsed.Username = args[i+1]
i++ i++
case "uuid": case "-U":
fallthrough
case "--uuid":
if len(args) == i+1 || args[i+1][0] == '-' { if len(args) == i+1 || args[i+1][0] == '-' {
err = errNoOptArg{ArgName: args[i]} err = errNoOptArg{ArgName: args[i]}
return return
} }
parsed.Uuid = args[i+1] parsed.Uuid = args[i+1]
i++ i++
case "java-Xmx": case "--java-Xmx":
if len(args) == i+1 || args[i+1][0] == '-' { if len(args) == i+1 || args[i+1][0] == '-' {
err = errNoOptArg{ArgName: args[i]} err = errNoOptArg{ArgName: args[i]}
return return
} }
parsed.JavaXmx = args[i+1] parsed.JavaXmx = args[i+1]
i++ i++
case "profile": case "--profile":
parsed.UseProfile = true parsed.UseProfile = true
default: default:
err = fmt.Errorf("an unknown option %s was provided", args[i]) err = fmt.Errorf("an unknown option %s was provided", args[i])
return 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")
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)
return
}
}
} }
return return
} }