Switch to urfave/cli/v2... again.

This commit is contained in:
Soren L. Hansen 2021-04-18 07:01:31 -07:00
parent 1fa987c518
commit c3c670b954
5 changed files with 14 additions and 28 deletions

10
go.mod
View File

@ -4,13 +4,13 @@ go 1.13
require ( require (
github.com/NYTimes/gziphandler v1.1.1 github.com/NYTimes/gziphandler v1.1.1
github.com/creack/pty v1.1.7 github.com/creack/pty v1.1.11
github.com/elazarl/go-bindata-assetfs v1.0.0 github.com/elazarl/go-bindata-assetfs v1.0.1
github.com/fatih/structs v1.1.0 github.com/fatih/structs v1.1.0
github.com/gorilla/websocket v1.4.1 github.com/gorilla/websocket v1.4.2
github.com/hashicorp/go-multierror v1.0.0 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/pkg/errors v0.9.1 github.com/pkg/errors v0.9.1
github.com/urfave/cli/v2 v2.3.0 github.com/urfave/cli/v2 v2.3.0
github.com/yudai/hcl v0.0.0-20151013225006-5fa2393b3552 github.com/yudai/hcl v0.0.0-20151013225006-5fa2393b3552
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae // indirect golang.org/x/sys v0.0.0-20210415045647-66c3f260301c // indirect
) )

2
go.sum
View File

@ -44,6 +44,8 @@ golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepx
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210412220455-f1c623a9e750 h1:ZBu6861dZq7xBnG1bn5SRU0vA8nx42at4+kP07FMTog= golang.org/x/sys v0.0.0-20210412220455-f1c623a9e750 h1:ZBu6861dZq7xBnG1bn5SRU0vA8nx42at4+kP07FMTog=
golang.org/x/sys v0.0.0-20210412220455-f1c623a9e750/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210412220455-f1c623a9e750/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210415045647-66c3f260301c h1:6L+uOeS3OQt/f4eFHXZcTxeZrGCuz+CLElgEBjbcTA4=
golang.org/x/sys v0.0.0-20210415045647-66c3f260301c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= 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/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

19
help.go
View File

@ -1,19 +0,0 @@
package main
var helpTemplate = `NAME:
{{.Name}} - {{.Usage}}
USAGE:
{{.Name}} [options] <command> [<arguments...>]
VERSION:
{{.Version}}{{if or .Author .Email}}
AUTHOR:{{if .Author}}
{{.Author}}{{if .Email}} - <{{.Email}}>{{end}}{{else}}
{{.Email}}{{end}}{{end}}
OPTIONS:
{{range .Flags}}{{.}}
{{end}}
`

View File

@ -22,10 +22,9 @@ func main() {
app.Name = "gotty" app.Name = "gotty"
app.Version = Version + "+" + CommitID app.Version = Version + "+" + CommitID
app.Usage = "Share your terminal as a web application" app.Usage = "Share your terminal as a web application"
app.HideHelp = true app.HideHelpCommand = true
cli.AppHelpTemplate = helpTemplate
appOptions := &server.Options{} appOptions := &server.Options{}
if err := utils.ApplyDefaultValues(appOptions); err != nil { if err := utils.ApplyDefaultValues(appOptions); err != nil {
exit(err, 1) exit(err, 1)
} }

View File

@ -28,8 +28,9 @@ func GenerateFlags(options ...interface{}) (flags []cli.Flag, mappings map[strin
mappings[flagName] = field.Name() mappings[flagName] = field.Name()
flagShortName := field.Tag("flagSName") flagShortName := field.Tag("flagSName")
var aliases []string
if flagShortName != "" { if flagShortName != "" {
flagName += ", " + flagShortName aliases = []string{flagShortName}
} }
flagDescription := field.Tag("flagDescribe") flagDescription := field.Tag("flagDescribe")
@ -41,12 +42,14 @@ func GenerateFlags(options ...interface{}) (flags []cli.Flag, mappings map[strin
Value: field.Value().(string), Value: field.Value().(string),
Usage: flagDescription, Usage: flagDescription,
EnvVars: []string{envName}, EnvVars: []string{envName},
Aliases: aliases,
}) })
case reflect.Bool: case reflect.Bool:
flags = append(flags, &cli.BoolFlag{ flags = append(flags, &cli.BoolFlag{
Name: flagName, Name: flagName,
Usage: flagDescription, Usage: flagDescription,
EnvVars: []string{envName}, EnvVars: []string{envName},
Aliases: aliases,
}) })
case reflect.Int: case reflect.Int:
flags = append(flags, &cli.IntFlag{ flags = append(flags, &cli.IntFlag{
@ -54,6 +57,7 @@ func GenerateFlags(options ...interface{}) (flags []cli.Flag, mappings map[strin
Value: field.Value().(int), Value: field.Value().(int),
Usage: flagDescription, Usage: flagDescription,
EnvVars: []string{envName}, EnvVars: []string{envName},
Aliases: aliases,
}) })
} }
} }