...

Source file src/k8s.io/kubectl/pkg/cmd/options/options.go

Documentation: k8s.io/kubectl/pkg/cmd/options

     1  /*
     2  Copyright 2016 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package options
    18  
    19  import (
    20  	"io"
    21  
    22  	"k8s.io/kubectl/pkg/util/i18n"
    23  	"k8s.io/kubectl/pkg/util/templates"
    24  
    25  	"github.com/spf13/cobra"
    26  )
    27  
    28  var (
    29  	optionsExample = templates.Examples(i18n.T(`
    30  		# Print flags inherited by all commands
    31  		kubectl options`))
    32  )
    33  
    34  // NewCmdOptions implements the options command
    35  func NewCmdOptions(out io.Writer) *cobra.Command {
    36  	cmd := &cobra.Command{
    37  		Use:     "options",
    38  		Short:   i18n.T("Print the list of flags inherited by all commands"),
    39  		Long:    i18n.T("Print the list of flags inherited by all commands"),
    40  		Example: optionsExample,
    41  		Run: func(cmd *cobra.Command, args []string) {
    42  			cmd.Usage()
    43  		},
    44  	}
    45  
    46  	// The `options` command needs write its output to the `out` stream
    47  	// (typically stdout). Without calling SetOutput here, the Usage()
    48  	// function call will fall back to stderr.
    49  	//
    50  	// See https://github.com/kubernetes/kubernetes/pull/46394 for details.
    51  	cmd.SetOut(out)
    52  	cmd.SetErr(out)
    53  
    54  	templates.UseOptionsTemplates(cmd)
    55  	return cmd
    56  }
    57  

View as plain text