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,101 +131,49 @@ 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
parsed.ShowVersion = true case "--version":
case "help": parsed.ShowVersion = true
parsed.ShowHelp = true case "-h":
case "demand-press-enter": fallthrough
parsed.DemandPressEnter = true case "--help":
case "username": parsed.ShowHelp = true
if len(args) == i+1 || args[i+1][0] == '-' { case "--demand-press-enter":
err = errNoOptArg{ArgName: args[i]} parsed.DemandPressEnter = true
return case "-u":
} fallthrough
parsed.Username = args[i+1] case "--username":
i++ if len(args) == i+1 || args[i+1][0] == '-' {
case "uuid": err = errNoOptArg{ArgName: args[i]}
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])
return return
} }
} else if args[i][0] == '-' && len(args[i]) > 1 { parsed.Username = args[i+1]
for _, option := range args[i][1:] { i++
switch option { case "-U":
case 'v': fallthrough
parsed.ShowVersion = true case "--uuid":
case 'h': if len(args) == i+1 || args[i+1][0] == '-' {
parsed.ShowHelp = true err = errNoOptArg{ArgName: args[i]}
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 return
} }
switch parsed.Command = args[i]; parsed.Command { parsed.Uuid = args[i+1]
case "i": i++
fallthrough case "--java-Xmx":
case "install": if len(args) == i+1 || args[i+1][0] == '-' {
fallthrough err = errNoOptArg{ArgName: args[i]}
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
} }
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 return