Record kubectl commands

This commit is contained in:
Janet Kuo
2016-01-22 10:33:23 -08:00
parent 210bac10c9
commit 5088d0e147
38 changed files with 277 additions and 11 deletions

View File

@@ -27,6 +27,7 @@ import (
"os/user"
"path"
"strconv"
"strings"
"time"
"github.com/emicklei/go-restful/swagger"
@@ -62,6 +63,7 @@ const (
type Factory struct {
clients *ClientCache
flags *pflag.FlagSet
cmd string
// Returns interfaces for dealing with arbitrary runtime.Objects.
Object func() (meta.RESTMapper, runtime.ObjectTyper)
@@ -182,6 +184,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
return &Factory{
clients: clients,
flags: flags,
cmd: recordCommand(os.Args),
Object: func() (meta.RESTMapper, runtime.ObjectTyper) {
cfg, err := clientConfig.ClientConfig()
@@ -472,6 +475,17 @@ func GetFirstPod(client *client.Client, namespace string, selector map[string]st
return pod, nil
}
func recordCommand(args []string) string {
if len(args) > 0 {
args[0] = "kubectl"
}
return strings.Join(args, " ")
}
func (f *Factory) Command() string {
return f.cmd
}
// BindFlags adds any flags that are common to all kubectl sub commands.
func (f *Factory) BindFlags(flags *pflag.FlagSet) {
// any flags defined by external projects (not part of pflags)