mirror of https://github.com/k3s-io/k3s
Merge pull request #54867 from juanvallejo/jvallejo/move-print-success-cmdutil-factory
Automatic merge from submit-queue (batch tested with PRs 55233, 55927, 55903, 54867, 55940). 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>. move cmd/util/printing.go#PrintSuccess to factory_builder.go **Release note**: ```release-note NONE ``` This patch is one in a series of patches that aims to move all printing functions to the `cmdutil.Factory` in order to make the factory the one-stop shop for accessing printers in the client. This PR is related to https://github.com/kubernetes/kubernetes/pull/50113 and aims to break that set of changes by introducing a portion of them in this commit in order to make them easier to review. @fabianofranz @mengqiy @shiywang @seans3pull/6/head
commit
fa3047880d
|
@ -291,7 +291,7 @@ func (o AnnotateOptions) RunAnnotate(f cmdutil.Factory, cmd *cobra.Command) erro
|
|||
if len(o.outputFormat) > 0 {
|
||||
return f.PrintObject(cmd, o.local, mapper, outputObj, o.out)
|
||||
}
|
||||
cmdutil.PrintSuccess(mapper, false, o.out, info.Mapping.Resource, info.Name, o.dryrun, "annotated")
|
||||
f.PrintSuccess(mapper, false, o.out, info.Mapping.Resource, info.Name, o.dryrun, "annotated")
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
|
|
@ -294,7 +294,7 @@ func RunApply(f cmdutil.Factory, cmd *cobra.Command, out, errOut io.Writer, opti
|
|||
if len(output) > 0 && !shortOutput {
|
||||
return f.PrintResourceInfoForCommand(cmd, info, out)
|
||||
}
|
||||
cmdutil.PrintSuccess(mapper, shortOutput, out, info.Mapping.Resource, info.Name, dryRun, "created")
|
||||
f.PrintSuccess(mapper, shortOutput, out, info.Mapping.Resource, info.Name, dryRun, "created")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -338,7 +338,7 @@ func RunApply(f cmdutil.Factory, cmd *cobra.Command, out, errOut io.Writer, opti
|
|||
|
||||
if string(patchBytes) == "{}" {
|
||||
count++
|
||||
cmdutil.PrintSuccess(mapper, shortOutput, out, info.Mapping.Resource, info.Name, false, "unchanged")
|
||||
f.PrintSuccess(mapper, shortOutput, out, info.Mapping.Resource, info.Name, false, "unchanged")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
@ -346,7 +346,7 @@ func RunApply(f cmdutil.Factory, cmd *cobra.Command, out, errOut io.Writer, opti
|
|||
if len(output) > 0 && !shortOutput {
|
||||
return f.PrintResourceInfoForCommand(cmd, info, out)
|
||||
}
|
||||
cmdutil.PrintSuccess(mapper, shortOutput, out, info.Mapping.Resource, info.Name, dryRun, "configured")
|
||||
f.PrintSuccess(mapper, shortOutput, out, info.Mapping.Resource, info.Name, dryRun, "configured")
|
||||
return nil
|
||||
})
|
||||
|
||||
|
@ -383,13 +383,13 @@ func RunApply(f cmdutil.Factory, cmd *cobra.Command, out, errOut io.Writer, opti
|
|||
|
||||
for n := range visitedNamespaces {
|
||||
for _, m := range namespacedRESTMappings {
|
||||
if err := p.prune(n, m, shortOutput, includeUninitialized); err != nil {
|
||||
if err := p.prune(f, n, m, shortOutput, includeUninitialized); err != nil {
|
||||
return fmt.Errorf("error pruning namespaced object %v: %v", m.GroupVersionKind, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, m := range nonNamespacedRESTMappings {
|
||||
if err := p.prune(metav1.NamespaceNone, m, shortOutput, includeUninitialized); err != nil {
|
||||
if err := p.prune(f, metav1.NamespaceNone, m, shortOutput, includeUninitialized); err != nil {
|
||||
return fmt.Errorf("error pruning nonNamespaced object %v: %v", m.GroupVersionKind, err)
|
||||
}
|
||||
}
|
||||
|
@ -463,7 +463,7 @@ type pruner struct {
|
|||
out io.Writer
|
||||
}
|
||||
|
||||
func (p *pruner) prune(namespace string, mapping *meta.RESTMapping, shortOutput, includeUninitialized bool) error {
|
||||
func (p *pruner) prune(f cmdutil.Factory, namespace string, mapping *meta.RESTMapping, shortOutput, includeUninitialized bool) error {
|
||||
c, err := p.clientFunc(mapping)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -513,7 +513,7 @@ func (p *pruner) prune(namespace string, mapping *meta.RESTMapping, shortOutput,
|
|||
return err
|
||||
}
|
||||
}
|
||||
cmdutil.PrintSuccess(p.mapper, shortOutput, p.out, mapping.Resource, name, p.dryRun, "pruned")
|
||||
f.PrintSuccess(p.mapper, shortOutput, p.out, mapping.Resource, name, p.dryRun, "pruned")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -192,14 +192,14 @@ func (o *SetLastAppliedOptions) RunSetLastApplied(f cmdutil.Factory, cmd *cobra.
|
|||
info.Refresh(patchedObj, false)
|
||||
return f.PrintResourceInfoForCommand(cmd, info, o.Out)
|
||||
}
|
||||
cmdutil.PrintSuccess(o.Mapper, o.ShortOutput, o.Out, info.Mapping.Resource, info.Name, o.DryRun, "configured")
|
||||
f.PrintSuccess(o.Mapper, o.ShortOutput, o.Out, info.Mapping.Resource, info.Name, o.DryRun, "configured")
|
||||
|
||||
} else {
|
||||
err := o.formatPrinter(o.Output, patch.Patch, o.Out)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cmdutil.PrintSuccess(o.Mapper, o.ShortOutput, o.Out, info.Mapping.Resource, info.Name, o.DryRun, "configured")
|
||||
f.PrintSuccess(o.Mapper, o.ShortOutput, o.Out, info.Mapping.Resource, info.Name, o.DryRun, "configured")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -119,7 +119,7 @@ func (o *ReconcileOptions) Complete(cmd *cobra.Command, f cmdutil.Factory, args
|
|||
if len(output) > 0 && !shortOutput {
|
||||
return f.PrintResourceInfoForCommand(cmd, info, o.Out)
|
||||
}
|
||||
cmdutil.PrintSuccess(mapper, shortOutput, o.Out, info.Mapping.Resource, info.Name, dryRun, "reconciled")
|
||||
f.PrintSuccess(mapper, shortOutput, o.Out, info.Mapping.Resource, info.Name, dryRun, "reconciled")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -179,7 +179,7 @@ func RunAutoscale(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []s
|
|||
return f.PrintObject(cmd, false, mapper, object, out)
|
||||
}
|
||||
|
||||
cmdutil.PrintSuccess(mapper, false, out, info.Mapping.Resource, info.Name, cmdutil.GetDryRunFlag(cmd), "autoscaled")
|
||||
f.PrintSuccess(mapper, false, out, info.Mapping.Resource, info.Name, cmdutil.GetDryRunFlag(cmd), "autoscaled")
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
|
|
|
@ -188,7 +188,7 @@ func (options *CertificateOptions) modifyCertificateCondition(f cmdutil.Factory,
|
|||
return err
|
||||
}
|
||||
found++
|
||||
cmdutil.PrintSuccess(mapper, options.outputStyle == "name", out, info.Mapping.Resource, info.Name, false, verb)
|
||||
f.PrintSuccess(mapper, options.outputStyle == "name", out, info.Mapping.Resource, info.Name, false, verb)
|
||||
return nil
|
||||
})
|
||||
if found == 0 {
|
||||
|
|
|
@ -236,7 +236,7 @@ func RunCreate(f cmdutil.Factory, cmd *cobra.Command, out, errOut io.Writer, opt
|
|||
f.PrintObjectSpecificMessage(info.Object, out)
|
||||
}
|
||||
|
||||
cmdutil.PrintSuccess(mapper, shortOutput, out, info.Mapping.Resource, info.Name, dryRun, "created")
|
||||
f.PrintSuccess(mapper, shortOutput, out, info.Mapping.Resource, info.Name, dryRun, "created")
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -348,7 +348,7 @@ func RunCreateSubcommand(f cmdutil.Factory, cmd *cobra.Command, out io.Writer, o
|
|||
}
|
||||
|
||||
if useShortOutput := options.OutputFormat == "name"; useShortOutput || len(options.OutputFormat) == 0 {
|
||||
cmdutil.PrintSuccess(mapper, useShortOutput, out, mapping.Resource, info.Name, options.DryRun, "created")
|
||||
f.PrintSuccess(mapper, useShortOutput, out, mapping.Resource, info.Name, options.DryRun, "created")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -172,7 +172,7 @@ func (c *CreateClusterRoleOptions) RunCreateRole() error {
|
|||
}
|
||||
|
||||
if useShortOutput := c.OutputFormat == "name"; useShortOutput || len(c.OutputFormat) == 0 {
|
||||
cmdutil.PrintSuccess(c.Mapper, useShortOutput, c.Out, "clusterroles", c.Name, c.DryRun, "created")
|
||||
c.PrintSuccess(c.Mapper, useShortOutput, c.Out, "clusterroles", c.Name, c.DryRun, "created")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -112,6 +112,7 @@ type CreateRoleOptions struct {
|
|||
Mapper meta.RESTMapper
|
||||
Out io.Writer
|
||||
PrintObject func(obj runtime.Object) error
|
||||
PrintSuccess func(mapper meta.RESTMapper, shortOutput bool, out io.Writer, resource, name string, dryRun bool, operation string)
|
||||
}
|
||||
|
||||
// Role is a command to ease creating Roles.
|
||||
|
@ -161,6 +162,7 @@ func (c *CreateRoleOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args
|
|||
}
|
||||
}
|
||||
c.Verbs = verbs
|
||||
c.PrintSuccess = f.PrintSuccess
|
||||
|
||||
// Support resource.group pattern. If no API Group specified, use "" as core API Group.
|
||||
// e.g. --resource=pods,deployments.extensions
|
||||
|
@ -292,7 +294,7 @@ func (c *CreateRoleOptions) RunCreateRole() error {
|
|||
}
|
||||
|
||||
if useShortOutput := c.OutputFormat == "name"; useShortOutput || len(c.OutputFormat) == 0 {
|
||||
cmdutil.PrintSuccess(c.Mapper, useShortOutput, c.Out, "roles", c.Name, c.DryRun, "created")
|
||||
c.PrintSuccess(c.Mapper, useShortOutput, c.Out, "roles", c.Name, c.DryRun, "created")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -239,7 +239,7 @@ func (o *DeleteOptions) RunDelete() error {
|
|||
if o.Cascade {
|
||||
return ReapResult(o.Result, o.f, o.Out, true, o.IgnoreNotFound, o.Timeout, o.GracePeriod, o.WaitForDeletion, shortOutput, o.Mapper, false)
|
||||
}
|
||||
return DeleteResult(o.Result, o.Out, o.IgnoreNotFound, o.GracePeriod, shortOutput, o.Mapper)
|
||||
return DeleteResult(o.Result, o.f, o.Out, o.IgnoreNotFound, o.GracePeriod, shortOutput, o.Mapper)
|
||||
}
|
||||
|
||||
func ReapResult(r *resource.Result, f cmdutil.Factory, out io.Writer, isDefaultDelete, ignoreNotFound bool, timeout time.Duration, gracePeriod int, waitForDeletion, shortOutput bool, mapper meta.RESTMapper, quiet bool) error {
|
||||
|
@ -257,7 +257,7 @@ func ReapResult(r *resource.Result, f cmdutil.Factory, out io.Writer, isDefaultD
|
|||
// If there is no reaper for this resources and the user didn't explicitly ask for stop.
|
||||
if kubectl.IsNoSuchReaperError(err) && isDefaultDelete {
|
||||
// No client side reaper found. Let the server do cascading deletion.
|
||||
return cascadingDeleteResource(info, out, shortOutput, mapper)
|
||||
return cascadingDeleteResource(info, f, out, shortOutput, mapper)
|
||||
}
|
||||
return cmdutil.AddSourceToErr("reaping", info.Source, err)
|
||||
}
|
||||
|
@ -274,7 +274,7 @@ func ReapResult(r *resource.Result, f cmdutil.Factory, out io.Writer, isDefaultD
|
|||
}
|
||||
}
|
||||
if !quiet {
|
||||
cmdutil.PrintSuccess(mapper, shortOutput, out, info.Mapping.Resource, info.Name, false, "deleted")
|
||||
f.PrintSuccess(mapper, shortOutput, out, info.Mapping.Resource, info.Name, false, "deleted")
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
@ -287,7 +287,7 @@ func ReapResult(r *resource.Result, f cmdutil.Factory, out io.Writer, isDefaultD
|
|||
return nil
|
||||
}
|
||||
|
||||
func DeleteResult(r *resource.Result, out io.Writer, ignoreNotFound bool, gracePeriod int, shortOutput bool, mapper meta.RESTMapper) error {
|
||||
func DeleteResult(r *resource.Result, f cmdutil.Factory, out io.Writer, ignoreNotFound bool, gracePeriod int, shortOutput bool, mapper meta.RESTMapper) error {
|
||||
found := 0
|
||||
if ignoreNotFound {
|
||||
r = r.IgnoreErrors(errors.IsNotFound)
|
||||
|
@ -305,7 +305,7 @@ func DeleteResult(r *resource.Result, out io.Writer, ignoreNotFound bool, graceP
|
|||
options = metav1.NewDeleteOptions(int64(gracePeriod))
|
||||
}
|
||||
options.OrphanDependents = &orphan
|
||||
return deleteResource(info, out, shortOutput, mapper, options)
|
||||
return deleteResource(info, f, out, shortOutput, mapper, options)
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -316,17 +316,17 @@ func DeleteResult(r *resource.Result, out io.Writer, ignoreNotFound bool, graceP
|
|||
return nil
|
||||
}
|
||||
|
||||
func cascadingDeleteResource(info *resource.Info, out io.Writer, shortOutput bool, mapper meta.RESTMapper) error {
|
||||
func cascadingDeleteResource(info *resource.Info, f cmdutil.Factory, out io.Writer, shortOutput bool, mapper meta.RESTMapper) error {
|
||||
falseVar := false
|
||||
deleteOptions := &metav1.DeleteOptions{OrphanDependents: &falseVar}
|
||||
return deleteResource(info, out, shortOutput, mapper, deleteOptions)
|
||||
return deleteResource(info, f, out, shortOutput, mapper, deleteOptions)
|
||||
}
|
||||
|
||||
func deleteResource(info *resource.Info, out io.Writer, shortOutput bool, mapper meta.RESTMapper, deleteOptions *metav1.DeleteOptions) error {
|
||||
func deleteResource(info *resource.Info, f cmdutil.Factory, out io.Writer, shortOutput bool, mapper meta.RESTMapper, deleteOptions *metav1.DeleteOptions) error {
|
||||
if err := resource.NewHelper(info.Client, info.Mapping).DeleteWithOptions(info.Namespace, info.Name, deleteOptions); err != nil {
|
||||
return cmdutil.AddSourceToErr("deleting", info.Source, err)
|
||||
}
|
||||
cmdutil.PrintSuccess(mapper, shortOutput, out, info.Mapping.Resource, info.Name, false, "deleted")
|
||||
f.PrintSuccess(mapper, shortOutput, out, info.Mapping.Resource, info.Name, false, "deleted")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -282,7 +282,7 @@ func (o *DrainOptions) RunDrain() error {
|
|||
}
|
||||
if err == nil || o.DryRun {
|
||||
drainedNodes.Insert(info.Name)
|
||||
cmdutil.PrintSuccess(o.mapper, false, o.Out, "node", info.Name, o.DryRun, "drained")
|
||||
o.Factory.PrintSuccess(o.mapper, false, o.Out, "node", info.Name, o.DryRun, "drained")
|
||||
} else {
|
||||
fmt.Fprintf(o.ErrOut, "error: unable to drain node %q, aborting command...\n\n", info.Name)
|
||||
remainingNodes := []string{}
|
||||
|
@ -626,7 +626,7 @@ func (o *DrainOptions) waitForDelete(pods []corev1.Pod, interval, timeout time.D
|
|||
for i, pod := range pods {
|
||||
p, err := getPodFn(pod.Namespace, pod.Name)
|
||||
if apierrors.IsNotFound(err) || (p != nil && p.ObjectMeta.UID != pod.ObjectMeta.UID) {
|
||||
cmdutil.PrintSuccess(o.mapper, false, o.Out, "pod", pod.Name, false, verbStr)
|
||||
o.Factory.PrintSuccess(o.mapper, false, o.Out, "pod", pod.Name, false, verbStr)
|
||||
continue
|
||||
} else if err != nil {
|
||||
return false, err
|
||||
|
@ -707,7 +707,7 @@ func (o *DrainOptions) RunCordonOrUncordon(desired bool) error {
|
|||
}
|
||||
unsched := node.Spec.Unschedulable
|
||||
if unsched == desired {
|
||||
cmdutil.PrintSuccess(o.mapper, false, o.Out, nodeInfo.Mapping.Resource, nodeInfo.Name, o.DryRun, already(desired))
|
||||
o.Factory.PrintSuccess(o.mapper, false, o.Out, nodeInfo.Mapping.Resource, nodeInfo.Name, o.DryRun, already(desired))
|
||||
} else {
|
||||
if !o.DryRun {
|
||||
helper := resource.NewHelper(o.restClient, nodeInfo.Mapping)
|
||||
|
@ -728,10 +728,10 @@ func (o *DrainOptions) RunCordonOrUncordon(desired bool) error {
|
|||
continue
|
||||
}
|
||||
}
|
||||
cmdutil.PrintSuccess(o.mapper, false, o.Out, nodeInfo.Mapping.Resource, nodeInfo.Name, o.DryRun, changed(desired))
|
||||
o.Factory.PrintSuccess(o.mapper, false, o.Out, nodeInfo.Mapping.Resource, nodeInfo.Name, o.DryRun, changed(desired))
|
||||
}
|
||||
} else {
|
||||
cmdutil.PrintSuccess(o.mapper, false, o.Out, nodeInfo.Mapping.Resource, nodeInfo.Name, o.DryRun, "skipped")
|
||||
o.Factory.PrintSuccess(o.mapper, false, o.Out, nodeInfo.Mapping.Resource, nodeInfo.Name, o.DryRun, "skipped")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -763,7 +763,7 @@ func TestDeletePods(t *testing.T) {
|
|||
|
||||
for _, test := range tests {
|
||||
f, _, _, _ := cmdtesting.NewAPIFactory()
|
||||
o := DrainOptions{}
|
||||
o := DrainOptions{Factory: f}
|
||||
o.mapper, _ = f.Object()
|
||||
o.Out = os.Stdout
|
||||
_, pods := createPods(false)
|
||||
|
|
|
@ -256,7 +256,7 @@ func RunExpose(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []stri
|
|||
if len(cmdutil.GetFlagString(cmd, "output")) > 0 {
|
||||
return f.PrintObject(cmd, false, mapper, object, out)
|
||||
}
|
||||
cmdutil.PrintSuccess(mapper, false, out, info.Mapping.Resource, info.Name, true, "exposed")
|
||||
f.PrintSuccess(mapper, false, out, info.Mapping.Resource, info.Name, true, "exposed")
|
||||
return nil
|
||||
}
|
||||
if err := kubectl.CreateOrUpdateAnnotation(cmdutil.GetFlagBool(cmd, cmdutil.ApplyAnnotationsFlag), info, f.JSONEncoder()); err != nil {
|
||||
|
@ -273,7 +273,7 @@ func RunExpose(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []stri
|
|||
return f.PrintObject(cmd, false, mapper, object, out)
|
||||
}
|
||||
|
||||
cmdutil.PrintSuccess(mapper, false, out, info.Mapping.Resource, info.Name, false, "exposed")
|
||||
f.PrintSuccess(mapper, false, out, info.Mapping.Resource, info.Name, false, "exposed")
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
|
|
|
@ -314,7 +314,7 @@ func (o *LabelOptions) RunLabel(f cmdutil.Factory, cmd *cobra.Command) error {
|
|||
if o.outputFormat != "" {
|
||||
return f.PrintObject(cmd, o.local, mapper, outputObj, o.out)
|
||||
}
|
||||
cmdutil.PrintSuccess(mapper, false, o.out, info.Mapping.Resource, info.Name, o.dryrun, dataChangeMsg)
|
||||
f.PrintSuccess(mapper, false, o.out, info.Mapping.Resource, info.Name, o.dryrun, dataChangeMsg)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
|
|
@ -226,7 +226,7 @@ func RunPatch(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []strin
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cmdutil.PrintSuccess(mapper, options.OutputFormat == "name", out, info.Mapping.Resource, info.Name, false, dataChangedMsg)
|
||||
f.PrintSuccess(mapper, options.OutputFormat == "name", out, info.Mapping.Resource, info.Name, false, dataChangedMsg)
|
||||
|
||||
// if object was not successfully patched, exit with error code 1
|
||||
if !didPatch {
|
||||
|
|
|
@ -160,7 +160,7 @@ func RunReplace(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []str
|
|||
|
||||
info.Refresh(obj, true)
|
||||
f.PrintObjectSpecificMessage(obj, out)
|
||||
cmdutil.PrintSuccess(mapper, shortOutput, out, info.Mapping.Resource, info.Name, false, "replaced")
|
||||
f.PrintSuccess(mapper, shortOutput, out, info.Mapping.Resource, info.Name, false, "replaced")
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
@ -223,7 +223,7 @@ func forceReplace(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []s
|
|||
glog.Warningf("\"cascade\" is set, kubectl will delete and re-create all resources managed by this resource (e.g. Pods created by a ReplicationController). Consider using \"kubectl rolling-update\" if you want to update a ReplicationController together with its Pods.")
|
||||
err = ReapResult(r, f, out, cmdutil.GetFlagBool(cmd, "cascade"), ignoreNotFound, timeout, gracePeriod, waitForDeletion, shortOutput, mapper, false)
|
||||
} else {
|
||||
err = DeleteResult(r, out, ignoreNotFound, gracePeriod, shortOutput, mapper)
|
||||
err = DeleteResult(r, f, out, ignoreNotFound, gracePeriod, shortOutput, mapper)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -284,7 +284,7 @@ func forceReplace(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []s
|
|||
count++
|
||||
info.Refresh(obj, true)
|
||||
f.PrintObjectSpecificMessage(obj, out)
|
||||
cmdutil.PrintSuccess(mapper, shortOutput, out, info.Mapping.Resource, info.Name, false, "replaced")
|
||||
f.PrintSuccess(mapper, shortOutput, out, info.Mapping.Resource, info.Name, false, "replaced")
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
|
|
|
@ -379,7 +379,7 @@ func RunRollingUpdate(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args
|
|||
if outputFormat != "" {
|
||||
return f.PrintObject(cmd, false, mapper, newRc, out)
|
||||
}
|
||||
cmdutil.PrintSuccess(mapper, false, out, "replicationcontrollers", oldName, dryrun, message)
|
||||
f.PrintSuccess(mapper, false, out, "replicationcontrollers", oldName, dryrun, message)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@ type PauseConfig struct {
|
|||
Encoder runtime.Encoder
|
||||
Infos []*resource.Info
|
||||
|
||||
PrintSuccess func(mapper meta.RESTMapper, shortOutput bool, out io.Writer, resource, name string, dryRun bool, operation string)
|
||||
Out io.Writer
|
||||
}
|
||||
|
||||
|
@ -100,6 +101,7 @@ func (o *PauseConfig) CompletePause(f cmdutil.Factory, cmd *cobra.Command, out i
|
|||
return cmdutil.UsageErrorf(cmd, "%s", cmd.Use)
|
||||
}
|
||||
|
||||
o.PrintSuccess = f.PrintSuccess
|
||||
o.Mapper, o.Typer = f.Object()
|
||||
o.Encoder = f.JSONEncoder()
|
||||
|
||||
|
@ -141,7 +143,7 @@ func (o PauseConfig) RunPause() error {
|
|||
}
|
||||
|
||||
if string(patch.Patch) == "{}" || len(patch.Patch) == 0 {
|
||||
cmdutil.PrintSuccess(o.Mapper, false, o.Out, info.Mapping.Resource, info.Name, false, "already paused")
|
||||
o.PrintSuccess(o.Mapper, false, o.Out, info.Mapping.Resource, info.Name, false, "already paused")
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -152,7 +154,7 @@ func (o PauseConfig) RunPause() error {
|
|||
}
|
||||
|
||||
info.Refresh(obj, true)
|
||||
cmdutil.PrintSuccess(o.Mapper, false, o.Out, info.Mapping.Resource, info.Name, false, "paused")
|
||||
o.PrintSuccess(o.Mapper, false, o.Out, info.Mapping.Resource, info.Name, false, "paused")
|
||||
}
|
||||
|
||||
return utilerrors.NewAggregate(allErrs)
|
||||
|
|
|
@ -45,6 +45,7 @@ type ResumeConfig struct {
|
|||
Encoder runtime.Encoder
|
||||
Infos []*resource.Info
|
||||
|
||||
PrintSuccess func(mapper meta.RESTMapper, shortOutput bool, out io.Writer, resource, name string, dryRun bool, operation string)
|
||||
Out io.Writer
|
||||
}
|
||||
|
||||
|
@ -98,6 +99,7 @@ func (o *ResumeConfig) CompleteResume(f cmdutil.Factory, cmd *cobra.Command, out
|
|||
return cmdutil.UsageErrorf(cmd, "%s", cmd.Use)
|
||||
}
|
||||
|
||||
o.PrintSuccess = f.PrintSuccess
|
||||
o.Mapper, o.Typer = f.Object()
|
||||
o.Encoder = f.JSONEncoder()
|
||||
|
||||
|
@ -146,7 +148,7 @@ func (o ResumeConfig) RunResume() error {
|
|||
}
|
||||
|
||||
if string(patch.Patch) == "{}" || len(patch.Patch) == 0 {
|
||||
cmdutil.PrintSuccess(o.Mapper, false, o.Out, info.Mapping.Resource, info.Name, false, "already resumed")
|
||||
o.PrintSuccess(o.Mapper, false, o.Out, info.Mapping.Resource, info.Name, false, "already resumed")
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -157,7 +159,7 @@ func (o ResumeConfig) RunResume() error {
|
|||
}
|
||||
|
||||
info.Refresh(obj, true)
|
||||
cmdutil.PrintSuccess(o.Mapper, false, o.Out, info.Mapping.Resource, info.Name, false, "resumed")
|
||||
o.PrintSuccess(o.Mapper, false, o.Out, info.Mapping.Resource, info.Name, false, "resumed")
|
||||
}
|
||||
|
||||
return utilerrors.NewAggregate(allErrs)
|
||||
|
|
|
@ -43,6 +43,7 @@ type UndoOptions struct {
|
|||
ToRevision int64
|
||||
DryRun bool
|
||||
|
||||
PrintSuccess func(mapper meta.RESTMapper, shortOutput bool, out io.Writer, resource, name string, dryRun bool, operation string)
|
||||
Out io.Writer
|
||||
}
|
||||
|
||||
|
@ -100,6 +101,7 @@ func (o *UndoOptions) CompleteUndo(f cmdutil.Factory, cmd *cobra.Command, out io
|
|||
return cmdutil.UsageErrorf(cmd, "Required resource not specified.")
|
||||
}
|
||||
|
||||
o.PrintSuccess = f.PrintSuccess
|
||||
o.ToRevision = cmdutil.GetFlagInt64(cmd, "to-revision")
|
||||
o.Mapper, o.Typer = f.Object()
|
||||
o.Out = out
|
||||
|
@ -146,7 +148,7 @@ func (o *UndoOptions) RunUndo() error {
|
|||
allErrs = append(allErrs, cmdutil.AddSourceToErr("undoing", info.Source, err))
|
||||
continue
|
||||
}
|
||||
cmdutil.PrintSuccess(o.Mapper, false, o.Out, info.Mapping.Resource, info.Name, false, result)
|
||||
o.PrintSuccess(o.Mapper, false, o.Out, info.Mapping.Resource, info.Name, false, result)
|
||||
}
|
||||
return utilerrors.NewAggregate(allErrs)
|
||||
}
|
||||
|
|
|
@ -404,7 +404,7 @@ func RunRun(f cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer, cmd *c
|
|||
if outputFormat != "" || cmdutil.GetDryRunFlag(cmd) {
|
||||
return f.PrintObject(cmd, false, runObject.Mapper, runObject.Object, cmdOut)
|
||||
}
|
||||
cmdutil.PrintSuccess(runObject.Mapper, false, cmdOut, runObject.Mapping.Resource, args[0], cmdutil.GetDryRunFlag(cmd), "created")
|
||||
f.PrintSuccess(runObject.Mapper, false, cmdOut, runObject.Mapping.Resource, args[0], cmdutil.GetDryRunFlag(cmd), "created")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -559,7 +559,7 @@ func generateService(f cmdutil.Factory, cmd *cobra.Command, args []string, servi
|
|||
}
|
||||
return runObject, nil
|
||||
}
|
||||
cmdutil.PrintSuccess(runObject.Mapper, false, out, runObject.Mapping.Resource, args[0], cmdutil.GetDryRunFlag(cmd), "created")
|
||||
f.PrintSuccess(runObject.Mapper, false, out, runObject.Mapping.Resource, args[0], cmdutil.GetDryRunFlag(cmd), "created")
|
||||
|
||||
return runObject, nil
|
||||
}
|
||||
|
|
|
@ -179,7 +179,7 @@ func RunScale(f cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []strin
|
|||
}
|
||||
}
|
||||
counter++
|
||||
cmdutil.PrintSuccess(mapper, shortOutput, out, info.Mapping.Resource, info.Name, false, "scaled")
|
||||
f.PrintSuccess(mapper, shortOutput, out, info.Mapping.Resource, info.Name, false, "scaled")
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
|
|
|
@ -443,7 +443,7 @@ func (o *EnvOptions) RunEnv(f cmdutil.Factory) error {
|
|||
continue
|
||||
}
|
||||
|
||||
cmdutil.PrintSuccess(o.Mapper, o.ShortOutput, o.Out, info.Mapping.Resource, info.Name, false, "env updated")
|
||||
f.PrintSuccess(o.Mapper, o.ShortOutput, o.Out, info.Mapping.Resource, info.Name, false, "env updated")
|
||||
}
|
||||
return utilerrors.NewAggregate(allErrs)
|
||||
}
|
||||
|
|
|
@ -54,6 +54,7 @@ type ImageOptions struct {
|
|||
Cmd *cobra.Command
|
||||
ResolveImage func(in string) (string, error)
|
||||
|
||||
PrintSuccess func(mapper meta.RESTMapper, shortOutput bool, out io.Writer, resource, name string, dryRun bool, operation string)
|
||||
PrintObject func(cmd *cobra.Command, isLocal bool, mapper meta.RESTMapper, obj runtime.Object, out io.Writer) error
|
||||
UpdatePodSpecForObject func(obj runtime.Object, fn func(*v1.PodSpec) error) (bool, error)
|
||||
Resources []string
|
||||
|
@ -116,6 +117,7 @@ func NewCmdImage(f cmdutil.Factory, out, err io.Writer) *cobra.Command {
|
|||
|
||||
func (o *ImageOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string) error {
|
||||
o.Mapper, _ = f.Object()
|
||||
o.PrintSuccess = f.PrintSuccess
|
||||
o.UpdatePodSpecForObject = f.UpdatePodSpecForObject
|
||||
o.Encoder = f.JSONEncoder()
|
||||
o.Decoder = f.Decoder(true)
|
||||
|
@ -279,7 +281,7 @@ func (o *ImageOptions) Run() error {
|
|||
}
|
||||
continue
|
||||
}
|
||||
cmdutil.PrintSuccess(o.Mapper, o.ShortOutput, o.Out, info.Mapping.Resource, info.Name, o.DryRun, "image updated")
|
||||
o.PrintSuccess(o.Mapper, o.ShortOutput, o.Out, info.Mapping.Resource, info.Name, o.DryRun, "image updated")
|
||||
}
|
||||
return utilerrors.NewAggregate(allErrs)
|
||||
}
|
||||
|
|
|
@ -80,6 +80,7 @@ type ResourcesOptions struct {
|
|||
Requests string
|
||||
ResourceRequirements v1.ResourceRequirements
|
||||
|
||||
PrintSuccess func(mapper meta.RESTMapper, shortOutput bool, out io.Writer, resource, name string, dryRun bool, operation string)
|
||||
PrintObject func(cmd *cobra.Command, isLocal bool, mapper meta.RESTMapper, obj runtime.Object, out io.Writer) error
|
||||
UpdatePodSpecForObject func(obj runtime.Object, fn func(*v1.PodSpec) error) (bool, error)
|
||||
Resources []string
|
||||
|
@ -127,6 +128,7 @@ func NewCmdResources(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.
|
|||
|
||||
func (o *ResourcesOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string) error {
|
||||
o.Mapper, _ = f.Object()
|
||||
o.PrintSuccess = f.PrintSuccess
|
||||
o.UpdatePodSpecForObject = f.UpdatePodSpecForObject
|
||||
o.Encoder = f.JSONEncoder()
|
||||
o.Output = cmdutil.GetFlagString(cmd, "output")
|
||||
|
@ -268,7 +270,7 @@ func (o *ResourcesOptions) Run() error {
|
|||
}
|
||||
continue
|
||||
}
|
||||
cmdutil.PrintSuccess(o.Mapper, shortOutput, o.Out, info.Mapping.Resource, info.Name, false, "resource requirements updated")
|
||||
o.PrintSuccess(o.Mapper, shortOutput, o.Out, info.Mapping.Resource, info.Name, false, "resource requirements updated")
|
||||
}
|
||||
return utilerrors.NewAggregate(allErrs)
|
||||
}
|
||||
|
|
|
@ -49,6 +49,7 @@ type SelectorOptions struct {
|
|||
selector *metav1.LabelSelector
|
||||
|
||||
out io.Writer
|
||||
PrintSuccess func(mapper meta.RESTMapper, shortOutput bool, out io.Writer, resource, name string, dryRun bool, operation string)
|
||||
PrintObject func(obj runtime.Object) error
|
||||
ClientForMapping func(mapping *meta.RESTMapping) (resource.RESTClient, error)
|
||||
|
||||
|
@ -114,6 +115,8 @@ func (o *SelectorOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args [
|
|||
return err
|
||||
}
|
||||
|
||||
o.PrintSuccess = f.PrintSuccess
|
||||
|
||||
o.changeCause = f.Command(cmd, false)
|
||||
mapper, _ := f.Object()
|
||||
o.mapper = mapper
|
||||
|
@ -217,7 +220,7 @@ func (o *SelectorOptions) RunSelector() error {
|
|||
if len(o.output) > 0 && !shortOutput {
|
||||
return o.PrintObject(patched)
|
||||
}
|
||||
cmdutil.PrintSuccess(o.mapper, shortOutput, o.out, info.Mapping.Resource, info.Name, o.dryrun, "selector updated")
|
||||
o.PrintSuccess(o.mapper, shortOutput, o.out, info.Mapping.Resource, info.Name, o.dryrun, "selector updated")
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
|
|
@ -70,6 +70,7 @@ type serviceAccountConfig struct {
|
|||
local bool
|
||||
PrintObject func(cmd *cobra.Command, isLocal bool, mapper meta.RESTMapper, obj runtime.Object, out io.Writer) error
|
||||
updatePodSpecForObject func(runtime.Object, func(*v1.PodSpec) error) (bool, error)
|
||||
printSuccess func(mapper meta.RESTMapper, shortOutput bool, out io.Writer, resource, name string, dryRun bool, operation string)
|
||||
infos []*resource.Info
|
||||
serviceAccountName string
|
||||
}
|
||||
|
@ -117,6 +118,7 @@ func (saConfig *serviceAccountConfig) Complete(f cmdutil.Factory, cmd *cobra.Com
|
|||
saConfig.PrintObject = f.PrintObject
|
||||
saConfig.cmd = cmd
|
||||
|
||||
saConfig.printSuccess = f.PrintSuccess
|
||||
cmdNamespace, enforceNamespace, err := f.DefaultNamespace()
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -191,7 +193,7 @@ func (saConfig *serviceAccountConfig) Run() error {
|
|||
}
|
||||
continue
|
||||
}
|
||||
cmdutil.PrintSuccess(saConfig.mapper, saConfig.shortOutput, saConfig.out, info.Mapping.Resource, info.Name, saConfig.dryRun, "serviceaccount updated")
|
||||
saConfig.printSuccess(saConfig.mapper, saConfig.shortOutput, saConfig.out, info.Mapping.Resource, info.Name, saConfig.dryRun, "serviceaccount updated")
|
||||
}
|
||||
return utilerrors.NewAggregate(patchErrs)
|
||||
}
|
||||
|
|
|
@ -258,7 +258,7 @@ func (o *SubjectOptions) Run(f cmdutil.Factory, fn updateSubjects) error {
|
|||
if len(o.Output) > 0 && !shortOutput {
|
||||
return o.PrintObject(o.Mapper, info.Object, o.Out)
|
||||
}
|
||||
cmdutil.PrintSuccess(o.Mapper, shortOutput, o.Out, info.Mapping.Resource, info.Name, false, "subjects updated")
|
||||
f.PrintSuccess(o.Mapper, shortOutput, o.Out, info.Mapping.Resource, info.Name, false, "subjects updated")
|
||||
}
|
||||
return utilerrors.NewAggregate(allErrs)
|
||||
}
|
||||
|
|
|
@ -278,7 +278,7 @@ func (o TaintOptions) RunTaint() error {
|
|||
return o.f.PrintObject(o.cmd, false, mapper, outputObj, o.out)
|
||||
}
|
||||
|
||||
cmdutil.PrintSuccess(mapper, false, o.out, info.Mapping.Resource, info.Name, false, operation)
|
||||
o.f.PrintSuccess(mapper, false, o.out, info.Mapping.Resource, info.Name, false, operation)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
|
|
@ -370,6 +370,29 @@ func (f *FakeFactory) PrintResourceInfoForCommand(cmd *cobra.Command, info *reso
|
|||
return printer.PrintObj(info.Object, out)
|
||||
}
|
||||
|
||||
func (f *FakeFactory) PrintSuccess(mapper meta.RESTMapper, shortOutput bool, out io.Writer, resource, name string, dryRun bool, operation string) {
|
||||
resource, _ = mapper.ResourceSingularizer(resource)
|
||||
dryRunMsg := ""
|
||||
if dryRun {
|
||||
dryRunMsg = " (dry run)"
|
||||
}
|
||||
if shortOutput {
|
||||
// -o name: prints resource/name
|
||||
if len(resource) > 0 {
|
||||
fmt.Fprintf(out, "%s/%s\n", resource, name)
|
||||
} else {
|
||||
fmt.Fprintf(out, "%s\n", name)
|
||||
}
|
||||
} else {
|
||||
// understandable output by default
|
||||
if len(resource) > 0 {
|
||||
fmt.Fprintf(out, "%s \"%s\" %s%s\n", resource, name, operation, dryRunMsg)
|
||||
} else {
|
||||
fmt.Fprintf(out, "\"%s\" %s%s\n", name, operation, dryRunMsg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (f *FakeFactory) Printer(mapping *meta.RESTMapping, options printers.PrintOptions) (printers.ResourcePrinter, error) {
|
||||
return f.tf.Printer, f.tf.Err
|
||||
}
|
||||
|
@ -713,6 +736,29 @@ func (f *fakeAPIFactory) PrintResourceInfoForCommand(cmd *cobra.Command, info *r
|
|||
return printer.PrintObj(info.Object, out)
|
||||
}
|
||||
|
||||
func (f *fakeAPIFactory) PrintSuccess(mapper meta.RESTMapper, shortOutput bool, out io.Writer, resource, name string, dryRun bool, operation string) {
|
||||
resource, _ = mapper.ResourceSingularizer(resource)
|
||||
dryRunMsg := ""
|
||||
if dryRun {
|
||||
dryRunMsg = " (dry run)"
|
||||
}
|
||||
if shortOutput {
|
||||
// -o name: prints resource/name
|
||||
if len(resource) > 0 {
|
||||
fmt.Fprintf(out, "%s/%s\n", resource, name)
|
||||
} else {
|
||||
fmt.Fprintf(out, "%s\n", name)
|
||||
}
|
||||
} else {
|
||||
// understandable output by default
|
||||
if len(resource) > 0 {
|
||||
fmt.Fprintf(out, "%s \"%s\" %s%s\n", resource, name, operation, dryRunMsg)
|
||||
} else {
|
||||
fmt.Fprintf(out, "\"%s\" %s%s\n", name, operation, dryRunMsg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (f *fakeAPIFactory) Describer(*meta.RESTMapping) (printers.Describer, error) {
|
||||
return f.tf.Describer, f.tf.Err
|
||||
}
|
||||
|
|
|
@ -410,14 +410,14 @@ func (o *EditOptions) visitToApplyEditPatch(originalInfos []*resource.Info, patc
|
|||
}
|
||||
|
||||
if reflect.DeepEqual(originalJS, editedJS) {
|
||||
cmdutil.PrintSuccess(o.Mapper, false, o.Out, info.Mapping.Resource, info.Name, false, "skipped")
|
||||
o.f.PrintSuccess(o.Mapper, false, o.Out, info.Mapping.Resource, info.Name, false, "skipped")
|
||||
return nil
|
||||
} else {
|
||||
err := o.annotationPatch(info)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cmdutil.PrintSuccess(o.Mapper, false, o.Out, info.Mapping.Resource, info.Name, false, "edited")
|
||||
o.f.PrintSuccess(o.Mapper, false, o.Out, info.Mapping.Resource, info.Name, false, "edited")
|
||||
return nil
|
||||
}
|
||||
})
|
||||
|
@ -536,7 +536,7 @@ func (o *EditOptions) visitToPatch(originalInfos []*resource.Info, patchVisitor
|
|||
|
||||
if reflect.DeepEqual(originalJS, editedJS) {
|
||||
// no edit, so just skip it.
|
||||
cmdutil.PrintSuccess(o.Mapper, false, o.Out, info.Mapping.Resource, info.Name, false, "skipped")
|
||||
o.f.PrintSuccess(o.Mapper, false, o.Out, info.Mapping.Resource, info.Name, false, "skipped")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -590,7 +590,7 @@ func (o *EditOptions) visitToPatch(originalInfos []*resource.Info, patchVisitor
|
|||
return nil
|
||||
}
|
||||
info.Refresh(patched, true)
|
||||
cmdutil.PrintSuccess(o.Mapper, false, o.Out, info.Mapping.Resource, info.Name, false, "edited")
|
||||
o.f.PrintSuccess(o.Mapper, false, o.Out, info.Mapping.Resource, info.Name, false, "edited")
|
||||
return nil
|
||||
})
|
||||
return err
|
||||
|
@ -601,7 +601,7 @@ func (o *EditOptions) visitToCreate(createVisitor resource.Visitor) error {
|
|||
if err := resource.CreateAndRefresh(info); err != nil {
|
||||
return err
|
||||
}
|
||||
cmdutil.PrintSuccess(o.Mapper, false, o.Out, info.Mapping.Resource, info.Name, false, "created")
|
||||
o.f.PrintSuccess(o.Mapper, false, o.Out, info.Mapping.Resource, info.Name, false, "created")
|
||||
return nil
|
||||
})
|
||||
return err
|
||||
|
|
|
@ -249,6 +249,8 @@ type BuilderFactory interface {
|
|||
// object passed is non-generic, it attempts to print the object using a HumanReadablePrinter.
|
||||
// Requires that printer flags have been added to cmd (see AddPrinterFlags).
|
||||
PrintResourceInfoForCommand(cmd *cobra.Command, info *resource.Info, out io.Writer) error
|
||||
// PrintSuccess prints message after finishing mutating operations
|
||||
PrintSuccess(mapper meta.RESTMapper, shortOutput bool, out io.Writer, resource, name string, dryRun bool, operation string)
|
||||
// One stop shopping for a structured Builder
|
||||
NewBuilder() *resource.Builder
|
||||
// One stop shopping for a unstructured Builder
|
||||
|
|
|
@ -107,6 +107,29 @@ func (f *ring2Factory) PrinterForMapping(cmd *cobra.Command, isLocal bool, outpu
|
|||
return printer, nil
|
||||
}
|
||||
|
||||
func (f *ring2Factory) PrintSuccess(mapper meta.RESTMapper, shortOutput bool, out io.Writer, resource, name string, dryRun bool, operation string) {
|
||||
resource, _ = mapper.ResourceSingularizer(resource)
|
||||
dryRunMsg := ""
|
||||
if dryRun {
|
||||
dryRunMsg = " (dry run)"
|
||||
}
|
||||
if shortOutput {
|
||||
// -o name: prints resource/name
|
||||
if len(resource) > 0 {
|
||||
fmt.Fprintf(out, "%s/%s\n", resource, name)
|
||||
} else {
|
||||
fmt.Fprintf(out, "%s\n", name)
|
||||
}
|
||||
} else {
|
||||
// understandable output by default
|
||||
if len(resource) > 0 {
|
||||
fmt.Fprintf(out, "%s \"%s\" %s%s\n", resource, name, operation, dryRunMsg)
|
||||
} else {
|
||||
fmt.Fprintf(out, "\"%s\" %s%s\n", name, operation, dryRunMsg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (f *ring2Factory) PrintObject(cmd *cobra.Command, isLocal bool, mapper meta.RESTMapper, obj runtime.Object, out io.Writer) error {
|
||||
// try to get a typed object
|
||||
_, typer := f.objectMappingFactory.Object()
|
||||
|
|
|
@ -18,7 +18,6 @@ package util
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"k8s.io/apimachinery/pkg/api/meta"
|
||||
|
@ -73,30 +72,6 @@ func AddNoHeadersFlags(cmd *cobra.Command) {
|
|||
cmd.Flags().Bool("no-headers", false, "When using the default or custom-column output format, don't print headers (default print headers).")
|
||||
}
|
||||
|
||||
// PrintSuccess prints message after finishing mutating operations
|
||||
func PrintSuccess(mapper meta.RESTMapper, shortOutput bool, out io.Writer, resource string, name string, dryRun bool, operation string) {
|
||||
resource, _ = mapper.ResourceSingularizer(resource)
|
||||
dryRunMsg := ""
|
||||
if dryRun {
|
||||
dryRunMsg = " (dry run)"
|
||||
}
|
||||
if shortOutput {
|
||||
// -o name: prints resource/name
|
||||
if len(resource) > 0 {
|
||||
fmt.Fprintf(out, "%s/%s\n", resource, name)
|
||||
} else {
|
||||
fmt.Fprintf(out, "%s\n", name)
|
||||
}
|
||||
} else {
|
||||
// understandable output by default
|
||||
if len(resource) > 0 {
|
||||
fmt.Fprintf(out, "%s \"%s\" %s%s\n", resource, name, operation, dryRunMsg)
|
||||
} else {
|
||||
fmt.Fprintf(out, "\"%s\" %s%s\n", name, operation, dryRunMsg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ValidateOutputArgs validates -o flag args for mutations
|
||||
func ValidateOutputArgs(cmd *cobra.Command) error {
|
||||
outputMode := GetFlagString(cmd, "output")
|
||||
|
|
Loading…
Reference in New Issue