mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
cmd/options: kubectl options
writes to out
stream
Previous behavior was to write to stderr (thanks to the fallback system in the Cobra library), which made it difficult to grep for flags. For example: kubectl options | grep recursive
This commit is contained in:
parent
382a170054
commit
0d65d9594c
@ -67,7 +67,7 @@ func NewKubeFedCommand(f cmdutil.Factory, in io.Reader, out, err io.Writer, defa
|
||||
templates.ActsAsRootCommand(cmds, filters, groups...)
|
||||
|
||||
cmds.AddCommand(kubectl.NewCmdVersion(f, out))
|
||||
cmds.AddCommand(kubectl.NewCmdOptions())
|
||||
cmds.AddCommand(kubectl.NewCmdOptions(out))
|
||||
|
||||
return cmds
|
||||
}
|
||||
|
@ -378,7 +378,7 @@ func NewKubectlCommand(f cmdutil.Factory, in io.Reader, out, err io.Writer) *cob
|
||||
cmds.AddCommand(NewCmdVersion(f, out))
|
||||
cmds.AddCommand(NewCmdApiVersions(f, out))
|
||||
cmds.AddCommand(deprecatedAlias("apiversions", NewCmdApiVersions(f, out)))
|
||||
cmds.AddCommand(NewCmdOptions())
|
||||
cmds.AddCommand(NewCmdOptions(out))
|
||||
|
||||
return cmds
|
||||
}
|
||||
|
@ -17,6 +17,8 @@ limitations under the License.
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
|
||||
"k8s.io/kubernetes/pkg/util/i18n"
|
||||
|
||||
@ -30,7 +32,7 @@ var (
|
||||
)
|
||||
|
||||
// NewCmdOptions implements the options command
|
||||
func NewCmdOptions() *cobra.Command {
|
||||
func NewCmdOptions(out io.Writer) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "options",
|
||||
Short: i18n.T("Print the list of flags inherited by all commands"),
|
||||
@ -41,7 +43,13 @@ func NewCmdOptions() *cobra.Command {
|
||||
},
|
||||
}
|
||||
|
||||
templates.UseOptionsTemplates(cmd)
|
||||
// The `options` command needs write its output to the `out` stream
|
||||
// (typically stdout). Without calling SetOutput here, the Usage()
|
||||
// function call will fall back to stderr.
|
||||
//
|
||||
// See https://github.com/kubernetes/kubernetes/pull/46394 for details.
|
||||
cmd.SetOutput(out)
|
||||
|
||||
templates.UseOptionsTemplates(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user