mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
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
This commit is contained in:
commit
8a40e5f77f
@ -241,6 +241,8 @@ func (o *GetOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []stri
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
printer = maybeWrapSortingPrinter(printer, isSorting)
|
||||
return printer.PrintObj, nil
|
||||
}
|
||||
|
||||
@ -738,3 +740,13 @@ func shouldGetNewPrinterForMapping(printer printers.ResourcePrinter, lastMapping
|
||||
func cmdSpecifiesOutputFmt(cmd *cobra.Command) bool {
|
||||
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user