github.com/paketo-buildpacks/packit@v1.3.2-0.20211206231111-86b75c657449/scribe/formatted_list.go (about)

     1  package scribe
     2  
     3  import (
     4  	"sort"
     5  	"strings"
     6  )
     7  
     8  // A FormattedList is a wrapper for []string to extend functionality.
     9  type FormattedList []string
    10  
    11  // Sorts the FormattedList alphabetically and then prints each item on its own
    12  // line.
    13  func (l FormattedList) String() string {
    14  	sort.Strings(l)
    15  
    16  	var builder strings.Builder
    17  	for i, elem := range l {
    18  		builder.WriteString(elem)
    19  		if i < len(l)-1 {
    20  			builder.WriteRune('\n')
    21  		}
    22  	}
    23  
    24  	return builder.String()
    25  }