Skip to content

Commit

Permalink
Add completion command
Browse files Browse the repository at this point in the history
  • Loading branch information
bharathi-tenneti committed Mar 18, 2020
1 parent 0317c63 commit 148f794
Show file tree
Hide file tree
Showing 6 changed files with 446 additions and 13 deletions.
53 changes: 53 additions & 0 deletions cmd/completion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
Copyright 2020 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import (
"os"

"github.com/spf13/cobra"
)

func newCompletionCmd() *cobra.Command {
completionCmd := &cobra.Command{
Use: "completion",
Short: "Generators for shell completions",
}
completionCmd.AddCommand(newZshCmd())
completionCmd.AddCommand(newBashCmd())
return completionCmd
}

func newBashCmd() *cobra.Command {
return &cobra.Command{
Use: "bash",
Short: "Generate bash completions",
RunE: func(cmd *cobra.Command, cmdArgs []string) error {
return cmd.Root().GenBashCompletion(os.Stdout)
},
}
}

func newZshCmd() *cobra.Command {
return &cobra.Command{
Use: "zsh",
Short: "Generate zsh completions",
RunE: func(cmd *cobra.Command, cmdArgs []string) error {
return cmd.Root().GenZshCompletion(os.Stdout)
},
}
}
3 changes: 3 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ func buildCmdTree() *cobra.Command {
// kubebuilder version
rootCmd.AddCommand(version.NewVersionCmd())

// kubebuilder completion
rootCmd.AddCommand(newCompletionCmd())

return rootCmd
}

Expand Down
16 changes: 10 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@ require (
github.com/gobuffalo/flect v0.2.0
github.com/golang/protobuf v1.3.2 // indirect
github.com/kr/pretty v0.1.0 // indirect
github.com/onsi/ginkgo v1.10.1
github.com/onsi/gomega v1.7.0
github.com/onsi/ginkgo v1.11.0
github.com/onsi/gomega v1.8.1
github.com/spf13/afero v1.2.2
github.com/spf13/cobra v0.0.5
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.4.0 // indirect
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9 // indirect
golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456 // indirect
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9
golang.org/x/sys v0.0.0-20190922100055-0a153f010e69 // indirect
golang.org/x/text v0.3.2 // indirect
golang.org/x/tools v0.0.0-20190920225731-5eefd052ad72
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/yaml.v2 v2.2.4 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/yaml.v2 v2.2.8 // indirect
k8s.io/api v0.17.4
k8s.io/apimachinery v0.17.4
k8s.io/client-go v11.0.0+incompatible
sigs.k8s.io/controller-runtime v0.5.1
sigs.k8s.io/yaml v1.1.0
)
Loading

0 comments on commit 148f794

Please sign in to comment.