Merge pull request #2164 from carlory/iostreams
take iostreams as a func parameter
This commit is contained in:
commit
6bd9f68a0d
|
@ -63,18 +63,11 @@ var (
|
||||||
%[1]s apply -f dir/ --all-clusters`)
|
%[1]s apply -f dir/ --all-clusters`)
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewCommandApplyOptions returns an initialized CommandApplyOptions instance
|
|
||||||
func NewCommandApplyOptions() *CommandApplyOptions {
|
|
||||||
streams := genericclioptions.IOStreams{In: getIn, Out: getOut, ErrOut: getErr}
|
|
||||||
flags := kubectlapply.NewApplyFlags(nil, streams)
|
|
||||||
return &CommandApplyOptions{
|
|
||||||
KubectlApplyFlags: flags,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewCmdApply creates the `apply` command
|
// NewCmdApply creates the `apply` command
|
||||||
func NewCmdApply(karmadaConfig KarmadaConfig, parentCommand string) *cobra.Command {
|
func NewCmdApply(karmadaConfig KarmadaConfig, parentCommand string, streams genericclioptions.IOStreams) *cobra.Command {
|
||||||
o := NewCommandApplyOptions()
|
o := &CommandApplyOptions{
|
||||||
|
KubectlApplyFlags: kubectlapply.NewApplyFlags(nil, streams),
|
||||||
|
}
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "apply (-f FILENAME | -k DIRECTORY)",
|
Use: "apply (-f FILENAME | -k DIRECTORY)",
|
||||||
Short: "Apply a configuration to a resource by file name or stdin and propagate them into member clusters",
|
Short: "Apply a configuration to a resource by file name or stdin and propagate them into member clusters",
|
||||||
|
|
|
@ -38,8 +38,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewCmdDescribe new describe command.
|
// NewCmdDescribe new describe command.
|
||||||
func NewCmdDescribe(karmadaConfig KarmadaConfig, parentCommand string) *cobra.Command {
|
func NewCmdDescribe(karmadaConfig KarmadaConfig, parentCommand string, streams genericclioptions.IOStreams) *cobra.Command {
|
||||||
ioStreams := genericclioptions.IOStreams{In: getIn, Out: getOut, ErrOut: getErr}
|
|
||||||
o := &CommandDescribeOptions{
|
o := &CommandDescribeOptions{
|
||||||
FilenameOptions: &resource.FilenameOptions{},
|
FilenameOptions: &resource.FilenameOptions{},
|
||||||
DescriberSettings: &describe.DescriberSettings{
|
DescriberSettings: &describe.DescriberSettings{
|
||||||
|
@ -49,7 +48,7 @@ func NewCmdDescribe(karmadaConfig KarmadaConfig, parentCommand string) *cobra.Co
|
||||||
|
|
||||||
CmdParent: parentCommand,
|
CmdParent: parentCommand,
|
||||||
|
|
||||||
IOStreams: ioStreams,
|
IOStreams: streams,
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
|
|
|
@ -40,8 +40,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewCmdExec new exec command.
|
// NewCmdExec new exec command.
|
||||||
func NewCmdExec(karmadaConfig KarmadaConfig, parentCommand string) *cobra.Command {
|
func NewCmdExec(karmadaConfig KarmadaConfig, parentCommand string, streams genericclioptions.IOStreams) *cobra.Command {
|
||||||
streams := genericclioptions.IOStreams{In: getIn, Out: getOut, ErrOut: getErr}
|
|
||||||
o := &ExecOptions{
|
o := &ExecOptions{
|
||||||
KubectlExecOptions: &kubectlexec.ExecOptions{
|
KubectlExecOptions: &kubectlexec.ExecOptions{
|
||||||
StreamOptions: kubectlexec.StreamOptions{
|
StreamOptions: kubectlexec.StreamOptions{
|
||||||
|
|
|
@ -49,10 +49,6 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
getIn = os.Stdin
|
|
||||||
getOut = os.Stdout
|
|
||||||
getErr = os.Stderr
|
|
||||||
|
|
||||||
podColumns = []metav1.TableColumnDefinition{
|
podColumns = []metav1.TableColumnDefinition{
|
||||||
{Name: "CLUSTER", Type: "string", Format: "", Priority: 0},
|
{Name: "CLUSTER", Type: "string", Format: "", Priority: 0},
|
||||||
{Name: "ADOPTION", Type: "string", Format: "", Priority: 0},
|
{Name: "ADOPTION", Type: "string", Format: "", Priority: 0},
|
||||||
|
@ -88,9 +84,8 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewCmdGet New get command
|
// NewCmdGet New get command
|
||||||
func NewCmdGet(karmadaConfig KarmadaConfig, parentCommand string) *cobra.Command {
|
func NewCmdGet(karmadaConfig KarmadaConfig, parentCommand string, streams genericclioptions.IOStreams) *cobra.Command {
|
||||||
ioStreams := genericclioptions.IOStreams{In: getIn, Out: getOut, ErrOut: getErr}
|
o := NewCommandGetOptions(streams)
|
||||||
o := NewCommandGetOptions(ioStreams)
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "get [NAME | -l label | -n namespace] [flags]",
|
Use: "get [NAME | -l label | -n namespace] [flags]",
|
||||||
Short: getShort,
|
Short: getShort,
|
||||||
|
|
|
@ -3,9 +3,11 @@ package karmadactl
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
|
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||||
"k8s.io/client-go/tools/clientcmd"
|
"k8s.io/client-go/tools/clientcmd"
|
||||||
apiserverflag "k8s.io/component-base/cli/flag"
|
apiserverflag "k8s.io/component-base/cli/flag"
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
|
@ -47,12 +49,12 @@ func NewKarmadaCtlCommand(cmdUse, parentCommand string) *cobra.Command {
|
||||||
_ = flag.CommandLine.Parse(nil)
|
_ = flag.CommandLine.Parse(nil)
|
||||||
|
|
||||||
karmadaConfig := NewKarmadaConfig(clientcmd.NewDefaultPathOptions())
|
karmadaConfig := NewKarmadaConfig(clientcmd.NewDefaultPathOptions())
|
||||||
|
ioStreams := genericclioptions.IOStreams{In: os.Stdin, Out: os.Stdout, ErrOut: os.Stderr}
|
||||||
groups := templates.CommandGroups{
|
groups := templates.CommandGroups{
|
||||||
{
|
{
|
||||||
Message: "Basic Commands:",
|
Message: "Basic Commands:",
|
||||||
Commands: []*cobra.Command{
|
Commands: []*cobra.Command{
|
||||||
NewCmdGet(karmadaConfig, parentCommand),
|
NewCmdGet(karmadaConfig, parentCommand, ioStreams),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -75,15 +77,15 @@ func NewKarmadaCtlCommand(cmdUse, parentCommand string) *cobra.Command {
|
||||||
{
|
{
|
||||||
Message: "Troubleshooting and Debugging Commands:",
|
Message: "Troubleshooting and Debugging Commands:",
|
||||||
Commands: []*cobra.Command{
|
Commands: []*cobra.Command{
|
||||||
NewCmdLogs(karmadaConfig, parentCommand),
|
NewCmdLogs(karmadaConfig, parentCommand, ioStreams),
|
||||||
NewCmdExec(karmadaConfig, parentCommand),
|
NewCmdExec(karmadaConfig, parentCommand, ioStreams),
|
||||||
NewCmdDescribe(karmadaConfig, parentCommand),
|
NewCmdDescribe(karmadaConfig, parentCommand, ioStreams),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Message: "Advanced Commands:",
|
Message: "Advanced Commands:",
|
||||||
Commands: []*cobra.Command{
|
Commands: []*cobra.Command{
|
||||||
NewCmdApply(karmadaConfig, parentCommand),
|
NewCmdApply(karmadaConfig, parentCommand, ioStreams),
|
||||||
NewCmdPromote(karmadaConfig, parentCommand),
|
NewCmdPromote(karmadaConfig, parentCommand),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -50,8 +50,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewCmdLogs new logs command.
|
// NewCmdLogs new logs command.
|
||||||
func NewCmdLogs(karmadaConfig KarmadaConfig, parentCommand string) *cobra.Command {
|
func NewCmdLogs(karmadaConfig KarmadaConfig, parentCommand string, streams genericclioptions.IOStreams) *cobra.Command {
|
||||||
streams := genericclioptions.IOStreams{In: getIn, Out: getOut, ErrOut: getErr}
|
|
||||||
o := &LogsOptions{
|
o := &LogsOptions{
|
||||||
KubectlLogsOptions: kubectllogs.NewLogsOptions(streams, false),
|
KubectlLogsOptions: kubectllogs.NewLogsOptions(streams, false),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue