@@ -449,10 +449,11 @@ func printFnResult(ctx context.Context, fnResult *fnresult.Result, opt *printer.
449449 for _ , item := range fnResult .Results {
450450 lines = append (lines , item .String ())
451451 }
452- ri := & MultiLineFormatter {
453- Title : "Results" ,
454- Lines : lines ,
455- TruncateOutput : printer .TruncateOutput ,
452+ ri := & SingleLineFormatter {
453+ Title : "[Results]" ,
454+ Lines : lines ,
455+ UseQuote : false ,
456+ Separator : ", " ,
456457 }
457458 pr .OptPrintf (opt , "%s" , ri .String ())
458459 }
@@ -470,13 +471,13 @@ func printFnExecErr(ctx context.Context, fnErr *ExecError) {
470471func printFnStderr (ctx context.Context , stdErr string ) {
471472 pr := printer .FromContextOrDie (ctx )
472473 if len (stdErr ) > 0 {
473- errLines := & MultiLineFormatter {
474- Title : "Stderr" ,
475- Lines : strings .Split (stdErr , "\n " ),
476- UseQuote : true ,
477- TruncateOutput : printer . TruncateOutput ,
474+ errLine := & SingleLineFormatter {
475+ Title : "Stderr" ,
476+ Lines : strings .Split (stdErr , "\n " ),
477+ UseQuote : false ,
478+ Separator : ", " ,
478479 }
479- pr .Printf ("%s" , errLines .String ())
480+ pr .Printf ("%s" , errLine .String ())
480481 }
481482}
482483
@@ -514,63 +515,27 @@ func enforcePathInvariants(nodes []*yaml.RNode) error {
514515 return nil
515516}
516517
517- // MultiLineFormatter knows how to format multiple lines in pretty format
518- // that can be displayed to an end user.
519- type MultiLineFormatter struct {
520- // Title under which lines need to be printed
521- Title string
522-
523- // Lines to be printed on the CLI.
524- Lines []string
525-
526- // TruncateOuput determines if output needs to be truncated or not.
527- TruncateOutput bool
528-
529- // MaxLines to be printed if truncation is enabled.
530- MaxLines int
531-
532- // UseQuote determines if line needs to be quoted or not
533- UseQuote bool
518+ type SingleLineFormatter struct {
519+ Title string // Label for the output
520+ Lines []string // Lines to be joined
521+ UseQuote bool // Whether to quote each line
522+ Separator string // Separator between lines (e.g., comma, space)
534523}
535524
536- // String returns multiline string.
537- func (ri * MultiLineFormatter ) String () string {
538- if ri .MaxLines == 0 {
539- ri .MaxLines = FnExecErrorTruncateLines
540- }
525+ func (sf * SingleLineFormatter ) String () string {
541526 strInterpolator := "%s"
542- if ri .UseQuote {
527+ if sf .UseQuote {
543528 strInterpolator = "%q"
544529 }
545530
546- var b strings.Builder
547-
548- b .WriteString (fmt .Sprintf (" %s:\n " , ri .Title ))
549- lineIndent := strings .Repeat (" " , FnExecErrorIndentation + 2 )
550- if ! ri .TruncateOutput {
551- // stderr string should have indentations
552- for _ , s := range ri .Lines {
553- // suppress newlines to avoid poor formatting
554- s = strings .ReplaceAll (s , "\n " , " " )
555- b .WriteString (fmt .Sprintf (lineIndent + strInterpolator + "\n " , s ))
556- }
557- return b .String ()
558- }
559- printedLines := 0
560- for i , s := range ri .Lines {
561- if i >= ri .MaxLines {
562- break
563- }
564- // suppress newlines to avoid poor formatting
565- s = strings .ReplaceAll (s , "\n " , " " )
566- b .WriteString (fmt .Sprintf (lineIndent + strInterpolator + "\n " , s ))
567- printedLines ++
531+ var formattedLines []string
532+ for _ , line := range sf .Lines {
533+ line = strings .ReplaceAll (line , "\n " , " " )
534+ line = strings .TrimSpace (line )
535+ formattedLines = append (formattedLines , fmt .Sprintf (strInterpolator , line ))
568536 }
569- truncatedLines := len (ri .Lines ) - printedLines
570- if truncatedLines > 0 {
571- b .WriteString (fmt .Sprintf (lineIndent + "...(%d line(s) truncated, use '--truncate-output=false' to disable)\n " , truncatedLines ))
572- }
573- return b .String ()
537+
538+ return fmt .Sprintf ("%s: %s" , sf .Title , strings .Join (formattedLines , sf .Separator ))
574539}
575540
576541func newFnConfig (fsys filesys.FileSystem , f * kptfilev1.Function , pkgPath types.UniquePath ) (* yaml.RNode , error ) {
0 commit comments