diff --git a/cmd/root.go b/cmd/root.go index 2a324c4a..d889cb47 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -23,6 +23,7 @@ package cmd import ( "fmt" + "io" "os" "strings" @@ -114,11 +115,11 @@ func initLogging() { } // Completion -var completionFunctions = map[string]interface{}{ - "bash": rootCmd.GenBashCompletion(os.Stdout), - "zsh": rootCmd.GenZshCompletion(os.Stdout), - "psh": rootCmd.GenPowerShellCompletion(os.Stdout), - "powershell": rootCmd.GenPowerShellCompletion(os.Stdout), +var completionFunctions = map[string]func(io.Writer) error{ + "bash": rootCmd.GenBashCompletion, + "zsh": rootCmd.GenZshCompletion, + "psh": rootCmd.GenPowerShellCompletion, + "powershell": rootCmd.GenPowerShellCompletion, } // NewCmdCompletion creates a new completion command @@ -132,7 +133,7 @@ func NewCmdCompletion() *cobra.Command { Args: cobra.ExactArgs(1), // TODO: add support for 0 args = auto detection Run: func(cmd *cobra.Command, args []string) { if f, ok := completionFunctions[args[0]]; ok { - if err := f; err != nil { + if err := f(os.Stdout); err != nil { log.Fatalf("Failed to generate completion script for shell '%s'", args[0]) } return diff --git a/go.mod b/go.mod index 26fe29f4..831d9781 100644 --- a/go.mod +++ b/go.mod @@ -6,8 +6,6 @@ require ( github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect github.com/Microsoft/go-winio v0.4.14 // indirect github.com/Microsoft/hcsshim v0.8.6 // indirect - github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect - github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect github.com/containerd/cgroups v0.0.0-20190923161937-abd0b19954a6 // indirect github.com/containerd/containerd v1.3.0-rc.2.0.20190924150618-aba201344ebf github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6 // indirect @@ -33,6 +31,7 @@ require ( github.com/opencontainers/runtime-spec v1.0.1 // indirect github.com/sirupsen/logrus v1.4.2 github.com/spf13/cobra v0.0.5 + github.com/stretchr/testify v1.4.0 // indirect github.com/syndtr/gocapability v0.0.0-20180916011248-d98352740cb2 // indirect go.etcd.io/bbolt v1.3.3 // indirect golang.org/x/net v0.0.0-20190812203447-cdfb69ac37fc // indirect @@ -40,7 +39,6 @@ require ( golang.org/x/text v0.3.2 // indirect golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 // indirect google.golang.org/grpc v1.23.0 // indirect - gopkg.in/alecthomas/kingpin.v2 v2.2.6 // indirect gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect gotest.tools v2.2.0+incompatible // indirect ) diff --git a/go.sum b/go.sum index 276b5277..fcb031a0 100644 --- a/go.sum +++ b/go.sum @@ -11,10 +11,6 @@ github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jB github.com/Microsoft/hcsshim v0.8.6 h1:ZfF0+zZeYdzMIVMZHKtDKJvLHj76XCuVae/jNkjj0IA= github.com/Microsoft/hcsshim v0.8.6/go.mod h1:Op3hHsoHPAvb6lceZHDtd9OkTew38wNoXnJs8iY7rUg= github.com/Shopify/logrus-bugsnag v0.0.0-20171204204709-577dee27f20d/go.mod h1:HI8ITrYtUY+O+ZhtlqUnD8+KwNPOyugEhfP9fdUIaEQ= -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-20190924025748-f65c72e2690d h1:UQZhZ2O0vMHr2cI+DC1Mbh0TJxzA3RcLoMsFw+aXw7E= -github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/aws/aws-sdk-go v1.15.11/go.mod h1:mFuSZ37Z9YOHbQEwBWztmVzqXrEkub65tZoCYDt7FT0= github.com/beorn7/perks v0.0.0-20160804104726-4c0e84591b9a/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= @@ -231,8 +227,6 @@ google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoA google.golang.org/grpc v0.0.0-20160317175043-d3ddb4469d5a/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= google.golang.org/grpc v1.23.0 h1:AzbTB6ux+okLTzP8Ru1Xs41C303zdcfEht7MQnYJt5A= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -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/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20141024133853-64131543e789/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=