mirror of
https://github.com/sorenisanerd/gotty.git
synced 2024-11-25 05:04:25 +00:00
Use v2 of urfave/cli
This commit is contained in:
parent
d9fe29e9c7
commit
1fa987c518
12
go.mod
12
go.mod
@ -4,13 +4,13 @@ go 1.13
|
||||
|
||||
require (
|
||||
github.com/NYTimes/gziphandler v1.1.1
|
||||
github.com/creack/pty v1.1.11
|
||||
github.com/elazarl/go-bindata-assetfs v1.0.1
|
||||
github.com/creack/pty v1.1.7
|
||||
github.com/elazarl/go-bindata-assetfs v1.0.0
|
||||
github.com/fatih/structs v1.1.0
|
||||
github.com/gorilla/websocket v1.4.2
|
||||
github.com/hashicorp/go-multierror v1.1.1 // indirect
|
||||
github.com/gorilla/websocket v1.4.1
|
||||
github.com/hashicorp/go-multierror v1.0.0 // indirect
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/urfave/cli v1.22.5
|
||||
github.com/urfave/cli/v2 v2.3.0
|
||||
github.com/yudai/hcl v0.0.0-20151013225006-5fa2393b3552
|
||||
golang.org/x/sys v0.0.0-20210412220455-f1c623a9e750 // indirect
|
||||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae // indirect
|
||||
)
|
||||
|
9
go.sum
9
go.sum
@ -36,15 +36,14 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/urfave/cli v1.22.2 h1:gsqYFH8bb9ekPA12kRo0hfjngWQjkJPlN9R0N78BoUo=
|
||||
github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
|
||||
github.com/urfave/cli v1.22.5 h1:lNq9sAHXK2qfdI8W+GRItjCEkI+2oR4d+MEHy1CKXoU=
|
||||
github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
|
||||
github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M=
|
||||
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
|
||||
github.com/yudai/hcl v0.0.0-20151013225006-5fa2393b3552 h1:tjsK9T2IA3d2FFNxzDP7AJf+EXhyuPd7PB4Z2HrtAoc=
|
||||
github.com/yudai/hcl v0.0.0-20151013225006-5fa2393b3552/go.mod h1:hg0ZaCmQL3rze1cH8Fh2g0a9q8vQs0uN8ESpePEwSEw=
|
||||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8=
|
||||
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/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/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
|
25
main.go
25
main.go
@ -9,7 +9,7 @@ import (
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/urfave/cli"
|
||||
cli "github.com/urfave/cli/v2"
|
||||
|
||||
"github.com/sorenisanerd/gotty/backend/localcommand"
|
||||
"github.com/sorenisanerd/gotty/pkg/homedir"
|
||||
@ -41,16 +41,16 @@ func main() {
|
||||
|
||||
app.Flags = append(
|
||||
cliFlags,
|
||||
cli.StringFlag{
|
||||
Name: "config",
|
||||
Value: "~/.gotty",
|
||||
Usage: "Config file path",
|
||||
EnvVar: "GOTTY_CONFIG",
|
||||
&cli.StringFlag{
|
||||
Name: "config",
|
||||
Value: "~/.gotty",
|
||||
Usage: "Config file path",
|
||||
EnvVars: []string{"GOTTY_CONFIG"},
|
||||
},
|
||||
)
|
||||
|
||||
app.Action = func(c *cli.Context) {
|
||||
if len(c.Args()) == 0 {
|
||||
app.Action = func(c *cli.Context) error {
|
||||
if c.NArg() == 0 {
|
||||
msg := "Error: No command given."
|
||||
cli.ShowAppHelp(c)
|
||||
exit(fmt.Errorf(msg), 1)
|
||||
@ -75,15 +75,15 @@ func main() {
|
||||
}
|
||||
|
||||
args := c.Args()
|
||||
factory, err := localcommand.NewFactory(args[0], args[1:], backendOptions)
|
||||
factory, err := localcommand.NewFactory(args.First(), args.Tail(), backendOptions)
|
||||
if err != nil {
|
||||
exit(err, 3)
|
||||
}
|
||||
|
||||
hostname, _ := os.Hostname()
|
||||
appOptions.TitleVariables = map[string]interface{}{
|
||||
"command": args[0],
|
||||
"argv": args[1:],
|
||||
"command": args.First(),
|
||||
"argv": args.Tail(),
|
||||
"hostname": hostname,
|
||||
}
|
||||
|
||||
@ -95,7 +95,7 @@ func main() {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
gCtx, gCancel := context.WithCancel(context.Background())
|
||||
|
||||
log.Printf("GoTTY is starting with command: %s", strings.Join(args, " "))
|
||||
log.Printf("GoTTY is starting with command: %s", strings.Join(args.Slice(), " "))
|
||||
|
||||
errs := make(chan error, 1)
|
||||
go func() {
|
||||
@ -108,6 +108,7 @@ func main() {
|
||||
exit(err, 8)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
app.Run(os.Args)
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/fatih/structs"
|
||||
"github.com/urfave/cli"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/yudai/hcl"
|
||||
|
||||
"github.com/sorenisanerd/gotty/pkg/homedir"
|
||||
@ -36,24 +36,24 @@ func GenerateFlags(options ...interface{}) (flags []cli.Flag, mappings map[strin
|
||||
|
||||
switch field.Kind() {
|
||||
case reflect.String:
|
||||
flags = append(flags, cli.StringFlag{
|
||||
Name: flagName,
|
||||
Value: field.Value().(string),
|
||||
Usage: flagDescription,
|
||||
EnvVar: envName,
|
||||
flags = append(flags, &cli.StringFlag{
|
||||
Name: flagName,
|
||||
Value: field.Value().(string),
|
||||
Usage: flagDescription,
|
||||
EnvVars: []string{envName},
|
||||
})
|
||||
case reflect.Bool:
|
||||
flags = append(flags, cli.BoolFlag{
|
||||
Name: flagName,
|
||||
Usage: flagDescription,
|
||||
EnvVar: envName,
|
||||
flags = append(flags, &cli.BoolFlag{
|
||||
Name: flagName,
|
||||
Usage: flagDescription,
|
||||
EnvVars: []string{envName},
|
||||
})
|
||||
case reflect.Int:
|
||||
flags = append(flags, cli.IntFlag{
|
||||
Name: flagName,
|
||||
Value: field.Value().(int),
|
||||
Usage: flagDescription,
|
||||
EnvVar: envName,
|
||||
flags = append(flags, &cli.IntFlag{
|
||||
Name: flagName,
|
||||
Value: field.Value().(int),
|
||||
Usage: flagDescription,
|
||||
EnvVars: []string{envName},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user