github.com/openshift/installer@v1.4.17/pkg/lineprinter/trimmer.go (about)

     1  package lineprinter
     2  
     3  import (
     4  	"strings"
     5  )
     6  
     7  // Trimmer is a Print wrapper that removes trailing newlines from the
     8  // final argument (if it is a string argument).  This is useful for
     9  // connecting a LinePrinter to a logger whose Print-analog does not
    10  // expect trailing newlines.
    11  type Trimmer struct {
    12  	WrappedPrint Print
    13  }
    14  
    15  // Print removes trailing newlines from the final argument (if it is a
    16  // string argument) and then passes the arguments through to
    17  // WrappedPrint.
    18  func (t *Trimmer) Print(args ...interface{}) {
    19  	if len(args) > 0 {
    20  		i := len(args) - 1
    21  		arg, ok := args[i].(string)
    22  		if ok {
    23  			args[i] = strings.TrimRight(arg, "\n")
    24  		}
    25  	}
    26  	t.WrappedPrint(args...)
    27  }