Allow --mapping argument to be repeated or comma-separated

This commit is contained in:
Geoff Bourne 2021-08-10 16:54:23 -05:00
parent 226f821598
commit 7779b866d1

View File

@ -30,7 +30,7 @@ type MetricsBackendConfig struct {
type Config struct {
Port int `default:"25565" usage:"The [port] bound to listen for Minecraft client connections"`
Mapping string `usage:"Comma-separated mappings of externalHostname=host:port"`
Mapping []string `usage:"Comma-separated or repeated mappings of externalHostname=host:port"`
ApiBinding string `usage:"The [host:port] bound for servicing API requests"`
Version bool `usage:"Output version and exit"`
CpuProfile string `usage:"Enables CPU profiling and writes to given path"`
@ -137,11 +137,9 @@ func main() {
logrus.Info("Stopping")
}
func parseMappings(val string) map[string]string {
func parseMappings(vals []string) map[string]string {
result := make(map[string]string)
if val != "" {
parts := strings.Split(val, ",")
for _, part := range parts {
for _, part := range vals {
keyValue := strings.Split(part, "=")
if len(keyValue) == 2 {
result[keyValue[0]] = keyValue[1]
@ -149,7 +147,6 @@ func parseMappings(val string) map[string]string {
logrus.WithField("part", part).Fatal("Invalid part of mapping")
}
}
}
return result
}