Unverified Commit 4ab24ede authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #62491 from deads2k/cli-25-out

Automatic merge from submit-queue (batch tested with PRs 58178, 62491, 60852). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. use standard interface functions for printers Updates the printObj funcs to be the standard resource printer interface we have. @kubernetes/sig-cli-misc
parents 72b7dacf 01609036
...@@ -117,7 +117,7 @@ type EnvOptions struct { ...@@ -117,7 +117,7 @@ type EnvOptions struct {
From string From string
Prefix string Prefix string
PrintObj func(runtime.Object) error PrintObj printers.ResourcePrinterFunc
Builder *resource.Builder Builder *resource.Builder
Infos []*resource.Info Infos []*resource.Info
...@@ -226,9 +226,7 @@ func (o *EnvOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []stri ...@@ -226,9 +226,7 @@ func (o *EnvOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []stri
if err != nil { if err != nil {
return err return err
} }
o.PrintObj = func(obj runtime.Object) error { o.PrintObj = printer.PrintObj
return printer.PrintObj(obj, o.Out)
}
if o.List && len(o.Output) > 0 { if o.List && len(o.Output) > 0 {
return cmdutil.UsageErrorf(o.Cmd, "--list and --output may not be specified together") return cmdutil.UsageErrorf(o.Cmd, "--list and --output may not be specified together")
...@@ -437,7 +435,7 @@ func (o *EnvOptions) RunEnv(f cmdutil.Factory) error { ...@@ -437,7 +435,7 @@ func (o *EnvOptions) RunEnv(f cmdutil.Factory) error {
} }
if o.Local || o.DryRun { if o.Local || o.DryRun {
if err := o.PrintObj(patch.Info.AsVersioned()); err != nil { if err := o.PrintObj(patch.Info.AsVersioned(), o.Out); err != nil {
return err return err
} }
continue continue
...@@ -456,7 +454,7 @@ func (o *EnvOptions) RunEnv(f cmdutil.Factory) error { ...@@ -456,7 +454,7 @@ func (o *EnvOptions) RunEnv(f cmdutil.Factory) error {
return fmt.Errorf("at least one environment variable must be provided") return fmt.Errorf("at least one environment variable must be provided")
} }
if err := o.PrintObj(info.AsVersioned()); err != nil { if err := o.PrintObj(info.AsVersioned(), o.Out); err != nil {
return err return err
} }
} }
......
...@@ -53,7 +53,7 @@ type ImageOptions struct { ...@@ -53,7 +53,7 @@ type ImageOptions struct {
Cmd *cobra.Command Cmd *cobra.Command
ResolveImage func(in string) (string, error) ResolveImage func(in string) (string, error)
PrintObj func(runtime.Object) error PrintObj printers.ResourcePrinterFunc
UpdatePodSpecForObject func(obj runtime.Object, fn func(*v1.PodSpec) error) (bool, error) UpdatePodSpecForObject func(obj runtime.Object, fn func(*v1.PodSpec) error) (bool, error)
Resources []string Resources []string
...@@ -136,9 +136,7 @@ func (o *ImageOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []st ...@@ -136,9 +136,7 @@ func (o *ImageOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []st
return err return err
} }
o.PrintObj = func(obj runtime.Object) error { o.PrintObj = printer.PrintObj
return printer.PrintObj(obj, o.Out)
}
cmdNamespace, enforceNamespace, err := f.DefaultNamespace() cmdNamespace, enforceNamespace, err := f.DefaultNamespace()
if err != nil { if err != nil {
...@@ -258,7 +256,7 @@ func (o *ImageOptions) Run() error { ...@@ -258,7 +256,7 @@ func (o *ImageOptions) Run() error {
} }
if o.Local || o.DryRun { if o.Local || o.DryRun {
if err := o.PrintObj(patch.Info.AsVersioned()); err != nil { if err := o.PrintObj(patch.Info.AsVersioned(), o.Out); err != nil {
return err return err
} }
continue continue
...@@ -283,7 +281,7 @@ func (o *ImageOptions) Run() error { ...@@ -283,7 +281,7 @@ func (o *ImageOptions) Run() error {
info.Refresh(obj, true) info.Refresh(obj, true)
if err := o.PrintObj(info.AsVersioned()); err != nil { if err := o.PrintObj(info.AsVersioned(), o.Out); err != nil {
return err return err
} }
} }
......
...@@ -79,7 +79,7 @@ type ResourcesOptions struct { ...@@ -79,7 +79,7 @@ type ResourcesOptions struct {
DryRun bool DryRun bool
PrintObj func(runtime.Object) error PrintObj printers.ResourcePrinterFunc
Limits string Limits string
Requests string Requests string
...@@ -155,9 +155,7 @@ func (o *ResourcesOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args ...@@ -155,9 +155,7 @@ func (o *ResourcesOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args
if err != nil { if err != nil {
return err return err
} }
o.PrintObj = func(obj runtime.Object) error { o.PrintObj = printer.PrintObj
return printer.PrintObj(obj, o.Out)
}
cmdNamespace, enforceNamespace, err := f.DefaultNamespace() cmdNamespace, enforceNamespace, err := f.DefaultNamespace()
if err != nil { if err != nil {
...@@ -262,7 +260,7 @@ func (o *ResourcesOptions) Run() error { ...@@ -262,7 +260,7 @@ func (o *ResourcesOptions) Run() error {
} }
if o.Local || o.DryRun { if o.Local || o.DryRun {
if err := o.PrintObj(patch.Info.AsVersioned()); err != nil { if err := o.PrintObj(patch.Info.AsVersioned(), o.Out); err != nil {
return err return err
} }
continue continue
...@@ -285,7 +283,7 @@ func (o *ResourcesOptions) Run() error { ...@@ -285,7 +283,7 @@ func (o *ResourcesOptions) Run() error {
} }
info.Refresh(obj, true) info.Refresh(obj, true)
if err := o.PrintObj(info.AsVersioned()); err != nil { if err := o.PrintObj(info.AsVersioned(), o.Out); err != nil {
return err return err
} }
} }
......
...@@ -55,7 +55,7 @@ type SelectorOptions struct { ...@@ -55,7 +55,7 @@ type SelectorOptions struct {
out io.Writer out io.Writer
ClientForMapping func(mapping *meta.RESTMapping) (resource.RESTClient, error) ClientForMapping func(mapping *meta.RESTMapping) (resource.RESTClient, error)
PrintObj func(runtime.Object) error PrintObj printers.ResourcePrinterFunc
builder *resource.Builder builder *resource.Builder
mapper meta.RESTMapper mapper meta.RESTMapper
...@@ -162,9 +162,7 @@ func (o *SelectorOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args [ ...@@ -162,9 +162,7 @@ func (o *SelectorOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args [
if err != nil { if err != nil {
return err return err
} }
o.PrintObj = func(obj runtime.Object) error { o.PrintObj = printer.PrintObj
return printer.PrintObj(obj, o.out)
}
o.ClientForMapping = func(mapping *meta.RESTMapping) (resource.RESTClient, error) { o.ClientForMapping = func(mapping *meta.RESTMapping) (resource.RESTClient, error) {
return f.ClientForMapping(mapping) return f.ClientForMapping(mapping)
...@@ -208,7 +206,7 @@ func (o *SelectorOptions) RunSelector() error { ...@@ -208,7 +206,7 @@ func (o *SelectorOptions) RunSelector() error {
return patch.Err return patch.Err
} }
if o.local || o.dryrun { if o.local || o.dryrun {
return o.PrintObj(info.Object) return o.PrintObj(info.Object, o.out)
} }
patched, err := resource.NewHelper(info.Client, info.Mapping).Patch(info.Namespace, info.Name, types.StrategicMergePatchType, patch.Patch) patched, err := resource.NewHelper(info.Client, info.Mapping).Patch(info.Namespace, info.Name, types.StrategicMergePatchType, patch.Patch)
...@@ -225,7 +223,7 @@ func (o *SelectorOptions) RunSelector() error { ...@@ -225,7 +223,7 @@ func (o *SelectorOptions) RunSelector() error {
} }
info.Refresh(patched, true) info.Refresh(patched, true)
return o.PrintObj(patch.Info.AsVersioned()) return o.PrintObj(patch.Info.AsVersioned(), o.out)
}) })
} }
......
...@@ -73,7 +73,7 @@ type serviceAccountConfig struct { ...@@ -73,7 +73,7 @@ type serviceAccountConfig struct {
infos []*resource.Info infos []*resource.Info
serviceAccountName string serviceAccountName string
PrintObj func(runtime.Object) error PrintObj printers.ResourcePrinterFunc
} }
// NewCmdServiceAccount returns the "set serviceaccount" command. // NewCmdServiceAccount returns the "set serviceaccount" command.
...@@ -127,9 +127,7 @@ func (saConfig *serviceAccountConfig) Complete(f cmdutil.Factory, cmd *cobra.Com ...@@ -127,9 +127,7 @@ func (saConfig *serviceAccountConfig) Complete(f cmdutil.Factory, cmd *cobra.Com
if err != nil { if err != nil {
return err return err
} }
saConfig.PrintObj = func(obj runtime.Object) error { saConfig.PrintObj = printer.PrintObj
return printer.PrintObj(obj, saConfig.out)
}
cmdNamespace, enforceNamespace, err := f.DefaultNamespace() cmdNamespace, enforceNamespace, err := f.DefaultNamespace()
if err != nil { if err != nil {
...@@ -180,7 +178,7 @@ func (saConfig *serviceAccountConfig) Run() error { ...@@ -180,7 +178,7 @@ func (saConfig *serviceAccountConfig) Run() error {
continue continue
} }
if saConfig.local || saConfig.dryRun { if saConfig.local || saConfig.dryRun {
if err := saConfig.PrintObj(patch.Info.AsVersioned()); err != nil { if err := saConfig.PrintObj(patch.Info.AsVersioned(), saConfig.out); err != nil {
return err return err
} }
continue continue
...@@ -199,7 +197,7 @@ func (saConfig *serviceAccountConfig) Run() error { ...@@ -199,7 +197,7 @@ func (saConfig *serviceAccountConfig) Run() error {
} }
} }
if err := saConfig.PrintObj(info.AsVersioned()); err != nil { if err := saConfig.PrintObj(info.AsVersioned(), saConfig.out); err != nil {
return err return err
} }
} }
......
...@@ -74,7 +74,7 @@ type SubjectOptions struct { ...@@ -74,7 +74,7 @@ type SubjectOptions struct {
Groups []string Groups []string
ServiceAccounts []string ServiceAccounts []string
PrintObj func(obj runtime.Object) error PrintObj printers.ResourcePrinterFunc
} }
func NewCmdSubject(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command { func NewCmdSubject(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command {
...@@ -124,9 +124,7 @@ func (o *SubjectOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args [] ...@@ -124,9 +124,7 @@ func (o *SubjectOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []
if err != nil { if err != nil {
return err return err
} }
o.PrintObj = func(obj runtime.Object) error { o.PrintObj = printer.PrintObj
return printer.PrintObj(obj, o.Out)
}
cmdNamespace, enforceNamespace, err := f.DefaultNamespace() cmdNamespace, enforceNamespace, err := f.DefaultNamespace()
if err != nil { if err != nil {
...@@ -251,7 +249,7 @@ func (o *SubjectOptions) Run(f cmdutil.Factory, fn updateSubjects) error { ...@@ -251,7 +249,7 @@ func (o *SubjectOptions) Run(f cmdutil.Factory, fn updateSubjects) error {
} }
if o.Local || o.DryRun { if o.Local || o.DryRun {
if err := o.PrintObj(info.Object); err != nil { if err := o.PrintObj(info.Object, o.Out); err != nil {
return err return err
} }
continue continue
...@@ -264,7 +262,7 @@ func (o *SubjectOptions) Run(f cmdutil.Factory, fn updateSubjects) error { ...@@ -264,7 +262,7 @@ func (o *SubjectOptions) Run(f cmdutil.Factory, fn updateSubjects) error {
} }
info.Refresh(obj, true) info.Refresh(obj, true)
return o.PrintObj(info.AsVersioned()) return o.PrintObj(info.AsVersioned(), o.Out)
} }
return utilerrors.NewAggregate(allErrs) return utilerrors.NewAggregate(allErrs)
} }
......
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