Fix linting issues in pkg/kubectl/cmd/version

Signed-off-by: ds-ms <desattir@microsoft.com>
This commit is contained in:
ds-ms 2019-01-24 12:25:08 +05:30
parent 1fc7b07bba
commit 0417d23a4c
2 changed files with 14 additions and 8 deletions

View File

@ -171,7 +171,6 @@ pkg/kubectl/cmd/testing
pkg/kubectl/cmd/top pkg/kubectl/cmd/top
pkg/kubectl/cmd/util pkg/kubectl/cmd/util
pkg/kubectl/cmd/util/openapi pkg/kubectl/cmd/util/openapi
pkg/kubectl/cmd/version
pkg/kubectl/cmd/wait pkg/kubectl/cmd/wait
pkg/kubectl/describe/versioned pkg/kubectl/describe/versioned
pkg/kubectl/generate pkg/kubectl/generate

View File

@ -34,6 +34,7 @@ import (
"k8s.io/kubernetes/pkg/version" "k8s.io/kubernetes/pkg/version"
) )
// Version is a struct for version information
type Version struct { type Version struct {
ClientVersion *apimachineryversion.Info `json:"clientVersion,omitempty" yaml:"clientVersion,omitempty"` ClientVersion *apimachineryversion.Info `json:"clientVersion,omitempty" yaml:"clientVersion,omitempty"`
ServerVersion *apimachineryversion.Info `json:"serverVersion,omitempty" yaml:"serverVersion,omitempty"` ServerVersion *apimachineryversion.Info `json:"serverVersion,omitempty" yaml:"serverVersion,omitempty"`
@ -45,7 +46,8 @@ var (
kubectl version`)) kubectl version`))
) )
type VersionOptions struct { // Options is a struct to support version command
type Options struct {
ClientOnly bool ClientOnly bool
Short bool Short bool
Output string Output string
@ -55,15 +57,17 @@ type VersionOptions struct {
genericclioptions.IOStreams genericclioptions.IOStreams
} }
func NewVersionOptions(ioStreams genericclioptions.IOStreams) *VersionOptions { // NewOptions returns initialized Options
return &VersionOptions{ func NewOptions(ioStreams genericclioptions.IOStreams) *Options {
return &Options{
IOStreams: ioStreams, IOStreams: ioStreams,
} }
} }
// NewCmdVersion returns a cobra command for fetching versions
func NewCmdVersion(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { func NewCmdVersion(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command {
o := NewVersionOptions(ioStreams) o := NewOptions(ioStreams)
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "version", Use: "version",
Short: i18n.T("Print the client and server version information"), Short: i18n.T("Print the client and server version information"),
@ -81,7 +85,8 @@ func NewCmdVersion(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *co
return cmd return cmd
} }
func (o *VersionOptions) Complete(f cmdutil.Factory, cmd *cobra.Command) error { // Complete completes all the required options
func (o *Options) Complete(f cmdutil.Factory, cmd *cobra.Command) error {
var err error var err error
o.discoveryClient, err = f.ToDiscoveryClient() o.discoveryClient, err = f.ToDiscoveryClient()
// if we had an empty rest.Config, continue and just print out client information. // if we had an empty rest.Config, continue and just print out client information.
@ -92,7 +97,8 @@ func (o *VersionOptions) Complete(f cmdutil.Factory, cmd *cobra.Command) error {
return nil return nil
} }
func (o *VersionOptions) Validate() error { // Validate validates the provided options
func (o *Options) Validate() error {
if o.Output != "" && o.Output != "yaml" && o.Output != "json" { if o.Output != "" && o.Output != "yaml" && o.Output != "json" {
return errors.New(`--output must be 'yaml' or 'json'`) return errors.New(`--output must be 'yaml' or 'json'`)
} }
@ -100,7 +106,8 @@ func (o *VersionOptions) Validate() error {
return nil return nil
} }
func (o *VersionOptions) Run() error { // Run executes version command
func (o *Options) Run() error {
var ( var (
serverVersion *apimachineryversion.Info serverVersion *apimachineryversion.Info
serverErr error serverErr error