Unverified Commit 8a40e5f7 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #64001 from juanvallejo/jvallejo/sort-on-generic-output

Automatic merge from submit-queue (batch tested with PRs 63770, 63776, 64001, 64028, 63984). 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>. sort on non-tabular output **Release note**: ```release-note NONE ``` Enables sorting objects when printing as json, yaml, etc. cc @soltysh
parents a915811a c87cd9c0
...@@ -241,6 +241,8 @@ func (o *GetOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []stri ...@@ -241,6 +241,8 @@ func (o *GetOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []stri
if err != nil { if err != nil {
return nil, err return nil, err
} }
printer = maybeWrapSortingPrinter(printer, isSorting)
return printer.PrintObj, nil return printer.PrintObj, nil
} }
...@@ -738,3 +740,13 @@ func shouldGetNewPrinterForMapping(printer printers.ResourcePrinter, lastMapping ...@@ -738,3 +740,13 @@ func shouldGetNewPrinterForMapping(printer printers.ResourcePrinter, lastMapping
func cmdSpecifiesOutputFmt(cmd *cobra.Command) bool { func cmdSpecifiesOutputFmt(cmd *cobra.Command) bool {
return cmdutil.GetFlagString(cmd, "output") != "" return cmdutil.GetFlagString(cmd, "output") != ""
} }
func maybeWrapSortingPrinter(printer printers.ResourcePrinter, sortBy string) printers.ResourcePrinter {
if len(sortBy) != 0 {
return &kubectl.SortingPrinter{
Delegate: printer,
SortField: fmt.Sprintf("%s", sortBy),
}
}
return printer
}
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