From 91ad5b4ec36236260b6e5e00b4278476d46b1c73 Mon Sep 17 00:00:00 2001 From: hurf Date: Tue, 24 Nov 2015 10:05:45 +0800 Subject: [PATCH] Cleanup logs command use 'logs' instead of 'log' --- pkg/kubectl/cmd/cmd.go | 2 +- pkg/kubectl/cmd/{log.go => logs.go} | 20 +++++++++---------- pkg/kubectl/cmd/{log_test.go => logs_test.go} | 6 +++--- 3 files changed, 14 insertions(+), 14 deletions(-) rename pkg/kubectl/cmd/{log.go => logs.go} (92%) rename pkg/kubectl/cmd/{log_test.go => logs_test.go} (97%) diff --git a/pkg/kubectl/cmd/cmd.go b/pkg/kubectl/cmd/cmd.go index f9903b99a55..e6f877c64d0 100644 --- a/pkg/kubectl/cmd/cmd.go +++ b/pkg/kubectl/cmd/cmd.go @@ -157,7 +157,7 @@ Find more information at https://github.com/kubernetes/kubernetes.`, cmds.AddCommand(NewCmdApply(f, out)) cmds.AddCommand(NewCmdNamespace(out)) - cmds.AddCommand(NewCmdLog(f, out)) + cmds.AddCommand(NewCmdLogs(f, out)) cmds.AddCommand(NewCmdRollingUpdate(f, out)) cmds.AddCommand(NewCmdScale(f, out)) diff --git a/pkg/kubectl/cmd/log.go b/pkg/kubectl/cmd/logs.go similarity index 92% rename from pkg/kubectl/cmd/log.go rename to pkg/kubectl/cmd/logs.go index 430511d6b30..5f1b47c6a52 100644 --- a/pkg/kubectl/cmd/log.go +++ b/pkg/kubectl/cmd/logs.go @@ -35,7 +35,7 @@ import ( ) const ( - log_example = `# Return snapshot logs from pod nginx with only one container + logs_example = `# Return snapshot logs from pod nginx with only one container $ kubectl logs nginx # Return snapshot of previous terminated ruby container logs from pod web-1 @@ -65,14 +65,14 @@ type LogsOptions struct { Out io.Writer } -// NewCmdLog creates a new pod log command -func NewCmdLog(f *cmdutil.Factory, out io.Writer) *cobra.Command { +// NewCmdLog creates a new pod logs command +func NewCmdLogs(f *cmdutil.Factory, out io.Writer) *cobra.Command { o := &LogsOptions{} cmd := &cobra.Command{ Use: "logs [-f] [-p] POD [-c CONTAINER]", Short: "Print the logs for a container in a pod.", Long: "Print the logs for a container in a pod. If the pod has only one container, the container name is optional.", - Example: log_example, + Example: logs_example, PreRun: func(cmd *cobra.Command, args []string) { if len(os.Args) > 1 && os.Args[1] == "log" { printDeprecationWarning("logs", "log") @@ -83,7 +83,7 @@ func NewCmdLog(f *cmdutil.Factory, out io.Writer) *cobra.Command { if err := o.Validate(); err != nil { cmdutil.CheckErr(cmdutil.UsageError(cmd, err.Error())) } - _, err := o.RunLog() + _, err := o.RunLogs() cmdutil.CheckErr(err) }, Aliases: []string{"log"}, @@ -163,19 +163,19 @@ func (o LogsOptions) Validate() error { if len(o.ResourceArg) == 0 { return errors.New("a pod must be specified") } - logOptions, ok := o.Options.(*api.PodLogOptions) + logsOptions, ok := o.Options.(*api.PodLogOptions) if !ok { - return errors.New("unexpected log options object") + return errors.New("unexpected logs options object") } - if errs := validation.ValidatePodLogOptions(logOptions); len(errs) > 0 { + if errs := validation.ValidatePodLogOptions(logsOptions); len(errs) > 0 { return errs.ToAggregate() } return nil } -// RunLog retrieves a pod log -func (o LogsOptions) RunLog() (int64, error) { +// RunLogs retrieves a pod log +func (o LogsOptions) RunLogs() (int64, error) { infos, err := resource.NewBuilder(o.Mapper, o.Typer, o.ClientMapper). NamespaceParam(o.Namespace).DefaultNamespace(). ResourceNames("pods", o.ResourceArg). diff --git a/pkg/kubectl/cmd/log_test.go b/pkg/kubectl/cmd/logs_test.go similarity index 97% rename from pkg/kubectl/cmd/log_test.go rename to pkg/kubectl/cmd/logs_test.go index da0332da62a..bb9e043bac7 100644 --- a/pkg/kubectl/cmd/log_test.go +++ b/pkg/kubectl/cmd/logs_test.go @@ -69,7 +69,7 @@ func TestLog(t *testing.T) { tf.ClientConfig = &client.Config{GroupVersion: &unversioned.GroupVersion{Version: test.version}} buf := bytes.NewBuffer([]byte{}) - cmd := NewCmdLog(f, buf) + cmd := NewCmdLogs(f, buf) cmd.Flags().Set("namespace", "test") cmd.Run(cmd, []string{"foo"}) @@ -119,7 +119,7 @@ func TestValidateLogFlags(t *testing.T) { }, } for _, test := range tests { - cmd := NewCmdLog(f, bytes.NewBuffer([]byte{})) + cmd := NewCmdLogs(f, bytes.NewBuffer([]byte{})) out := "" for flag, value := range test.flags { cmd.Flags().Set(flag, value) @@ -130,7 +130,7 @@ func TestValidateLogFlags(t *testing.T) { cmd.Run = func(cmd *cobra.Command, args []string) { o.Complete(f, os.Stdout, cmd, args) out = o.Validate().Error() - o.RunLog() + o.RunLogs() } cmd.Run(cmd, []string{"foo"})