sort on non-tabular output

pull/8/head
juanvallejo 2018-05-17 17:42:34 -04:00
parent 0ef96cbaf4
commit c87cd9c0f6
1 changed files with 12 additions and 0 deletions

View File

@ -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
}