From f93f1f611ff035164f3141547ab387f9a824693f Mon Sep 17 00:00:00 2001 From: Cassandra Date: Fri, 30 Aug 2019 17:18:04 +0200 Subject: [PATCH] Add kingpin flag parsing (#9) --- cmd/protoplex/protoplex.go | 23 ++++++++++++----------- go.mod | 8 +++++++- go.sum | 17 +++++++++++++++++ 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/cmd/protoplex/protoplex.go b/cmd/protoplex/protoplex.go index 6acb801..f2cc7ab 100644 --- a/cmd/protoplex/protoplex.go +++ b/cmd/protoplex/protoplex.go @@ -1,30 +1,31 @@ package main import ( - "flag" "os" "github.com/Pandentia/protoplex/protoplex" "github.com/Pandentia/protoplex/protoplex/protocols" "github.com/rs/zerolog" + "gopkg.in/alecthomas/kingpin.v2" ) func main() { + app := kingpin.New("protoplex", "A fast and simple protocol multiplexer.") logger := zerolog.New(os.Stdout).With().Timestamp().Logger() - bind := flag.String("bind", "0.0.0.0:8443", "The address to bind to") - verbose := flag.Bool("verbose", false, "Whether to be verbose") - pretty := flag.Bool("pretty", false, "Whether to enable pretty printing") + bind := app.Flag("bind", "The address to bind to").Short('b').Default("0.0.0.0:8443").String() + verbose := app.Flag("verbose", "Enables debug logging").Short('v').Bool() + pretty := app.Flag("pretty", "Enables pretty logging").Short('p').Bool() - ssh := flag.String("ssh", "", "The SSH server address") - tls := flag.String("tls", "", "The TLS/HTTPS server address") - openvpn := flag.String("ovpn", "", "The OpenVPN server address") - http := flag.String("http", "", "The HTTP server address") - socks5 := flag.String("socks5", "", "The SOCKS5 server address") - socks4 := flag.String("socks4", "", "The SOCKS4 server address") + ssh := app.Flag("ssh", "The SSH server address").String() + tls := app.Flag("tls", "The TLS/HTTPS server address").String() + openvpn := app.Flag("ovpn", "The OpenVPN server address").String() + http := app.Flag("http", "The HTTP server address").String() + socks5 := app.Flag("socks5", "The SOCKS5 server address").String() + socks4 := app.Flag("socks4", "The SOCKS4 server address").String() // stRelay := flag.String("strelay", "", "The Syncthing Relay server address") - flag.Parse() + app.Parse(os.Args[1:]) if *pretty { logger = logger.Output(zerolog.ConsoleWriter{Out: os.Stderr}) diff --git a/go.mod b/go.mod index 4e0df20..6d83b3b 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,10 @@ module github.com/Pandentia/protoplex go 1.12 -require github.com/rs/zerolog v1.15.0 +require ( + github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect + github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4 // indirect + github.com/rs/zerolog v1.15.0 + github.com/stretchr/testify v1.4.0 // indirect + gopkg.in/alecthomas/kingpin.v2 v2.2.6 +) diff --git a/go.sum b/go.sum index 3dcc830..3b3396b 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,19 @@ +github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM= +github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4 h1:Hs82Z41s6SdL1CELW+XaDYmOH4hkBN4/N9og/AsOv7E= +github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= github.com/rs/zerolog v1.15.0 h1:uPRuwkWF4J6fGsJ2R0Gn2jB1EQiav9k3S6CSdygQJXY= github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= @@ -10,3 +21,9 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/tools v0.0.0-20190425163242-31fd60d6bfdc/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc= +gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=