@@ -487,13 +487,6 @@ func (o *GetOptions) Run(f cmdutil.Factory, cmd *cobra.Command, args []string) e
487
487
488
488
objs := make ([]runtime.Object , len (infos ))
489
489
for ix := range infos {
490
- // TODO: remove this and just pass the table objects to the printer opaquely once `info.Object.(*metav1beta1.Table)` checking is removed below
491
- if o .ServerPrint {
492
- table , err := decodeIntoTable (infos [ix ].Object )
493
- if err == nil {
494
- infos [ix ].Object = table
495
- }
496
- }
497
490
objs [ix ] = infos [ix ].Object
498
491
}
499
492
@@ -513,8 +506,11 @@ func (o *GetOptions) Run(f cmdutil.Factory, cmd *cobra.Command, args []string) e
513
506
514
507
var printer printers.ResourcePrinter
515
508
var lastMapping * meta.RESTMapping
516
- nonEmptyObjCount := 0
517
- w := utilprinters .GetNewTabWriter (o .Out )
509
+
510
+ // track if we write any output
511
+ trackingWriter := & trackingWriterWrapper {Delegate : o .Out }
512
+
513
+ w := utilprinters .GetNewTabWriter (trackingWriter )
518
514
for ix := range objs {
519
515
var mapping * meta.RESTMapping
520
516
var info * resource.Info
@@ -526,16 +522,6 @@ func (o *GetOptions) Run(f cmdutil.Factory, cmd *cobra.Command, args []string) e
526
522
mapping = info .Mapping
527
523
}
528
524
529
- // if dealing with a table that has no rows, skip remaining steps
530
- // and avoid printing an unnecessary newline
531
- if table , isTable := info .Object .(* metav1beta1.Table ); isTable {
532
- if len (table .Rows ) == 0 {
533
- continue
534
- }
535
- }
536
-
537
- nonEmptyObjCount ++
538
-
539
525
printWithNamespace := o .AllNamespaces
540
526
541
527
if mapping != nil && mapping .Scope .Name () == meta .RESTScopeNameRoot {
@@ -582,12 +568,23 @@ func (o *GetOptions) Run(f cmdutil.Factory, cmd *cobra.Command, args []string) e
582
568
}
583
569
}
584
570
w .Flush ()
585
- if nonEmptyObjCount == 0 && ! o .IgnoreNotFound && len (allErrs ) == 0 {
571
+ if trackingWriter .Written == 0 && ! o .IgnoreNotFound && len (allErrs ) == 0 {
572
+ // if we wrote no output, and had no errors, and are not ignoring NotFound, be sure we output something
586
573
fmt .Fprintln (o .ErrOut , "No resources found." )
587
574
}
588
575
return utilerrors .NewAggregate (allErrs )
589
576
}
590
577
578
+ type trackingWriterWrapper struct {
579
+ Delegate io.Writer
580
+ Written int
581
+ }
582
+
583
+ func (t * trackingWriterWrapper ) Write (p []byte ) (n int , err error ) {
584
+ t .Written += len (p )
585
+ return t .Delegate .Write (p )
586
+ }
587
+
591
588
// raw makes a simple HTTP request to the provided path on the server using the default
592
589
// credentials.
593
590
func (o * GetOptions ) raw (f cmdutil.Factory ) error {
0 commit comments