Switch golang flag's to allow for glog argument access

This commit is contained in:
Geoff Bourne 2018-05-27 15:36:01 -05:00
parent 702a5d5e49
commit d9a0c70a31
3 changed files with 34 additions and 42 deletions

View File

@ -2,27 +2,24 @@ package main
import ( import (
"context" "context"
"flag"
"fmt" "fmt"
"github.com/alecthomas/kingpin"
"github.com/itzg/mc-router/server" "github.com/itzg/mc-router/server"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"net" "net"
"os" "os"
"os/signal" "os/signal"
"strconv" "strconv"
"strings"
) )
var ( var (
port = kingpin.Flag("port", "The port bound to listen for Minecraft client connections"). port = flag.Int("port", 25565, "The port bound to listen for Minecraft client connections")
Default("25565").Int() apiBinding = flag.String("api-binding", "", "The host:port bound for servicing API requests")
apiBinding = kingpin.Flag("api-binding", "The host:port bound for servicing API requests"). mappings = flag.String("mapping", "", "Comma-separated mappings of externalHostname=host:port")
String() versionFlag = flag.Bool("version", false, "Output version and exit")
mappings = kingpin.Flag("mapping", "Mapping of external hostname to internal server host:port"). kubeConfigFile = flag.String("kube-config", "", "The path to a kubernetes configuration file")
StringMap() inKubeCluster = flag.Bool("in-kube-cluster", false, "Use in-cluster kubernetes config")
versionFlag = kingpin.Flag("version", "Output version and exit").
Bool()
kubeConfigFile = kingpin.Flag("kube-config", "The path to a kubernetes configuration file").String()
inKubeCluster = kingpin.Flag("in-kube-cluster", "Use in-cluster kubernetes config").Bool()
) )
var ( var (
@ -36,7 +33,7 @@ func showVersion() {
} }
func main() { func main() {
kingpin.Parse() flag.Parse()
if *versionFlag { if *versionFlag {
showVersion() showVersion()
@ -48,7 +45,7 @@ func main() {
c := make(chan os.Signal, 1) c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt) signal.Notify(c, os.Interrupt)
server.Routes.RegisterAll(*mappings) server.Routes.RegisterAll(parseMappings(*mappings))
server.Connector.StartAcceptingConnections(ctx, net.JoinHostPort("", strconv.Itoa(*port))) server.Connector.StartAcceptingConnections(ctx, net.JoinHostPort("", strconv.Itoa(*port)))
@ -77,3 +74,19 @@ func main() {
logrus.Info("Stopping") logrus.Info("Stopping")
cancel() cancel()
} }
func parseMappings(val string) map[string]string {
result := make(map[string]string)
if val != "" {
parts := strings.Split(val, ",")
for _, part := range parts {
keyValue := strings.Split(part, "=")
if len(keyValue) == 2 {
result[keyValue[0]] = keyValue[1]
}
logrus.WithField("part", part).Fatal("Invalid part of mapping")
}
}
return result
}

35
glide.lock generated
View File

@ -1,14 +1,6 @@
hash: d0042501db8c547ec44ff6828ff8b0c7d08561d95311f4c62cf8014e6a02e97e hash: 6d3afa029b5a24a153f556f8a2ca493f4f1de4c41f438d2309a32a922e2d9408
updated: 2018-05-26T11:09:13.8257578-05:00 updated: 2018-05-27T14:41:00.6804253-05:00
imports: imports:
- name: github.com/alecthomas/kingpin
version: 947dcec5ba9c011838740e680966fd7087a71d0d
- name: github.com/alecthomas/template
version: a0175ee3bccc567396460bf5acd36800cb10c49c
subpackages:
- parse
- name: github.com/alecthomas/units
version: 2efee857e7cfd4f3d0138cc3cbb1b4966962b93a
- name: github.com/davecgh/go-spew - name: github.com/davecgh/go-spew
version: 782f4967f2dc4564575ca782fe2d04090b5faca8 version: 782f4967f2dc4564575ca782fe2d04090b5faca8
subpackages: subpackages:
@ -59,14 +51,13 @@ imports:
- name: github.com/spf13/pflag - name: github.com/spf13/pflag
version: 4c012f6dcd9546820e378d0bdda4d8fc772cdfea version: 4c012f6dcd9546820e378d0bdda4d8fc772cdfea
- name: golang.org/x/crypto - name: golang.org/x/crypto
version: a3beeb748656e13e54256fd2cde19e058f41f60f version: ab813273cd59e1333f7ae7bff5d027d4aadf528c
subpackages: subpackages:
- ssh/terminal - ssh/terminal
- name: golang.org/x/net - name: golang.org/x/net
version: 1c05540f6879653db88113bc4a2b70aec4bd491f version: 1c05540f6879653db88113bc4a2b70aec4bd491f
subpackages: subpackages:
- context - context
- context/ctxhttp
- http2 - http2
- http2/hpack - http2/hpack
- idna - idna
@ -126,17 +117,10 @@ imports:
- name: k8s.io/apimachinery - name: k8s.io/apimachinery
version: 302974c03f7e50f16561ba237db776ab93594ef6 version: 302974c03f7e50f16561ba237db776ab93594ef6
subpackages: subpackages:
- pkg/api/equality
- pkg/api/errors - pkg/api/errors
- pkg/api/meta - pkg/api/meta
- pkg/api/resource - pkg/api/resource
- pkg/api/testing - pkg/api/resource
- pkg/api/testing/fuzzer
- pkg/api/testing/roundtrip
- pkg/apimachinery
- pkg/apimachinery/announced
- pkg/apimachinery/registered
- pkg/apis/meta/fuzzer
- pkg/apis/meta/internalversion - pkg/apis/meta/internalversion
- pkg/apis/meta/v1 - pkg/apis/meta/v1
- pkg/apis/meta/v1/unstructured - pkg/apis/meta/v1/unstructured
@ -146,6 +130,8 @@ imports:
- pkg/fields - pkg/fields
- pkg/labels - pkg/labels
- pkg/runtime - pkg/runtime
- pkg/runtime
- pkg/runtime/schema
- pkg/runtime/schema - pkg/runtime/schema
- pkg/runtime/serializer - pkg/runtime/serializer
- pkg/runtime/serializer/json - pkg/runtime/serializer/json
@ -155,29 +141,24 @@ imports:
- pkg/runtime/serializer/versioning - pkg/runtime/serializer/versioning
- pkg/selection - pkg/selection
- pkg/types - pkg/types
- pkg/types
- pkg/util/cache - pkg/util/cache
- pkg/util/clock - pkg/util/clock
- pkg/util/diff - pkg/util/diff
- pkg/util/errors - pkg/util/errors
- pkg/util/framer - pkg/util/framer
- pkg/util/httpstream - pkg/util/intstr
- pkg/util/httpstream/spdy
- pkg/util/intstr - pkg/util/intstr
- pkg/util/json - pkg/util/json
- pkg/util/mergepatch
- pkg/util/net - pkg/util/net
- pkg/util/remotecommand
- pkg/util/runtime - pkg/util/runtime
- pkg/util/sets - pkg/util/sets
- pkg/util/strategicpatch
- pkg/util/validation - pkg/util/validation
- pkg/util/validation/field - pkg/util/validation/field
- pkg/util/wait - pkg/util/wait
- pkg/util/yaml - pkg/util/yaml
- pkg/version - pkg/version
- pkg/watch - pkg/watch
- third_party/forked/golang/json
- third_party/forked/golang/netutil
- third_party/forked/golang/reflect - third_party/forked/golang/reflect
- name: k8s.io/client-go - name: k8s.io/client-go
version: 23781f4d6632d88e869066eaebb743857aa1ef9b version: 23781f4d6632d88e869066eaebb743857aa1ef9b

View File

@ -1,7 +1,5 @@
package: github.com/itzg/mc-router package: github.com/itzg/mc-router
import: import:
- package: github.com/alecthomas/kingpin
version: ^2.2.6
- package: github.com/gorilla/mux - package: github.com/gorilla/mux
version: ^1.6.2 version: ^1.6.2
- package: github.com/pkg/errors - package: github.com/pkg/errors