Use TabWriter to keep output of "kubectl get xx -w" aligned.

Use TabWriter to keep output of "kubectl get xx -w" aligned.
This commit is contained in:
Xing Zhou 2017-03-22 13:26:18 +08:00
parent b54077b0c5
commit a76f55403b

View File

@ -245,16 +245,19 @@ func RunGet(f cmdutil.Factory, out, errOut io.Writer, cmd *cobra.Command, args [
// print the current object
if !isWatchOnly {
var objsToPrint []runtime.Object
writer := printers.GetNewTabWriter(out)
if isList {
objsToPrint, _ = meta.ExtractList(obj)
} else {
objsToPrint = append(objsToPrint, obj)
}
for _, objToPrint := range objsToPrint {
if err := printer.PrintObj(objToPrint, out); err != nil {
if err := printer.PrintObj(objToPrint, writer); err != nil {
return fmt.Errorf("unable to output the provided object: %v", err)
}
}
writer.Flush()
}
// print watched changes