Commit 0d65d959 authored by Alexander Campbell's avatar Alexander Campbell

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
parent 382a1700
...@@ -67,7 +67,7 @@ func NewKubeFedCommand(f cmdutil.Factory, in io.Reader, out, err io.Writer, defa ...@@ -67,7 +67,7 @@ func NewKubeFedCommand(f cmdutil.Factory, in io.Reader, out, err io.Writer, defa
templates.ActsAsRootCommand(cmds, filters, groups...) templates.ActsAsRootCommand(cmds, filters, groups...)
cmds.AddCommand(kubectl.NewCmdVersion(f, out)) cmds.AddCommand(kubectl.NewCmdVersion(f, out))
cmds.AddCommand(kubectl.NewCmdOptions()) cmds.AddCommand(kubectl.NewCmdOptions(out))
return cmds return cmds
} }
......
...@@ -378,7 +378,7 @@ func NewKubectlCommand(f cmdutil.Factory, in io.Reader, out, err io.Writer) *cob ...@@ -378,7 +378,7 @@ func NewKubectlCommand(f cmdutil.Factory, in io.Reader, out, err io.Writer) *cob
cmds.AddCommand(NewCmdVersion(f, out)) cmds.AddCommand(NewCmdVersion(f, out))
cmds.AddCommand(NewCmdApiVersions(f, out)) cmds.AddCommand(NewCmdApiVersions(f, out))
cmds.AddCommand(deprecatedAlias("apiversions", NewCmdApiVersions(f, out))) cmds.AddCommand(deprecatedAlias("apiversions", NewCmdApiVersions(f, out)))
cmds.AddCommand(NewCmdOptions()) cmds.AddCommand(NewCmdOptions(out))
return cmds return cmds
} }
......
...@@ -17,6 +17,8 @@ limitations under the License. ...@@ -17,6 +17,8 @@ limitations under the License.
package cmd package cmd
import ( import (
"io"
"k8s.io/kubernetes/pkg/kubectl/cmd/templates" "k8s.io/kubernetes/pkg/kubectl/cmd/templates"
"k8s.io/kubernetes/pkg/util/i18n" "k8s.io/kubernetes/pkg/util/i18n"
...@@ -30,7 +32,7 @@ var ( ...@@ -30,7 +32,7 @@ var (
) )
// NewCmdOptions implements the options command // NewCmdOptions implements the options command
func NewCmdOptions() *cobra.Command { func NewCmdOptions(out io.Writer) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "options", Use: "options",
Short: i18n.T("Print the list of flags inherited by all commands"), Short: i18n.T("Print the list of flags inherited by all commands"),
...@@ -41,7 +43,13 @@ func NewCmdOptions() *cobra.Command { ...@@ -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 return cmd
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment