Skip to content

Instantly share code, notes, and snippets.

@juanvallejo
Last active July 2, 2018 15:47
Show Gist options
  • Select an option

  • Save juanvallejo/a606d1f7e01965cbcde1ad2d2d789834 to your computer and use it in GitHub Desktop.

Select an option

Save juanvallejo/a606d1f7e01965cbcde1ad2d2d789834 to your computer and use it in GitHub Desktop.
Commands that bound the --template flag in kubectl 1.10 and contained the word `go-template` in --output description
diff --git a/pkg/kubectl/cmd/cmd.go b/pkg/kubectl/cmd/cmd.go
index 3bdd843b97..21ff8addc5 100644
--- a/pkg/kubectl/cmd/cmd.go
+++ b/pkg/kubectl/cmd/cmd.go
@@ -20,6 +20,7 @@ import (
"fmt"
"io"
"os"
+ "strings"
"k8s.io/apiserver/pkg/util/flag"
"k8s.io/client-go/tools/clientcmd"
@@ -213,7 +214,34 @@ var (
)
func NewDefaultKubectlCommand() *cobra.Command {
- return NewKubectlCommand(cmdutil.NewFactory(nil), os.Stdin, os.Stdout, os.Stderr)
+ cmd := NewKubectlCommand(cmdutil.NewFactory(nil), os.Stdin, os.Stdout, os.Stderr)
+
+ left := []*cobra.Command{}
+ for _, c := range cmd.Commands() {
+ left = append(left, c)
+ }
+ for len(left) > 0 {
+ c := left[0]
+ left = left[1:]
+
+ // append children to left
+ left = append(left, c.Commands()...)
+
+ // determine if any flags include --template support
+ if f := c.Flag("template"); f != nil {
+ if fo := c.Flag("output"); fo != nil {
+ if strings.Contains(fo.Usage, "go-template") {
+ fmt.Printf("- %s\n", c.CommandPath())
+ }
+ }
+ }
+ }
+
+ return cmd
}
// NewKubectlCommand creates the `kubectl` command and its nested children.
@@ -351,7 +379,7 @@ func NewKubectlCommand(f cmdutil.Factory, in io.Reader, out, err io.Writer) *cob
}
func runHelp(cmd *cobra.Command, args []string) {
- cmd.Help()
+ //cmd.Help()
}
func printDeprecationWarning(errOut io.Writer, command, alias string) {
- kubectl annotate
- kubectl apply
- kubectl autoscale
- kubectl convert
- kubectl create
- kubectl expose
- kubectl get
- kubectl label
- kubectl patch
- kubectl rolling-update
- kubectl run
- kubectl run-container
- kubectl taint
- kubectl apply set-last-applied
- kubectl auth reconcile
- kubectl config view
- kubectl create clusterrole
- kubectl create clusterrolebinding
- kubectl create configmap
- kubectl create deployment
- kubectl create job
- kubectl create namespace
- kubectl create poddisruptionbudget
- kubectl create priorityclass
- kubectl create quota
- kubectl create role
- kubectl create rolebinding
- kubectl create serviceaccount
- kubectl set env
- kubectl set image
- kubectl set resources
- kubectl set selector
- kubectl set serviceaccount
- kubectl set subject
- kubectl create secret docker-registry
- kubectl create secret generic
- kubectl create secret tls
- kubectl create service clusterip
- kubectl create service externalname
- kubectl create service loadbalancer
- kubectl create service nodeport
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment