Skip to content

Commit

Permalink
Merge pull request #1663 from simonbaird/text-output-image-ref-wrap-t…
Browse files Browse the repository at this point in the history
…weak

Don't wrap image ref in text output
  • Loading branch information
simonbaird authored Jun 5, 2024
2 parents bbdf3a4 + faba907 commit 0862dbe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion internal/applicationsnapshot/templates/_results.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{{- colorIndicator $type }} {{ colorText $type (printf "[%s] %s" $type .Metadata.code) }}{{ nl -}}

{{- if $imageRef -}}
{{- indentWrap $indent $wrap (printf "ImageRef: %s" $imageRef ) }}{{ nl -}}
{{- indent $indent (printf "ImageRef: %s" $imageRef ) }}{{ nl -}}
{{- end -}}

{{/* For a success the message is generally just "Pass" so don't show it */}}
Expand Down
20 changes: 15 additions & 5 deletions internal/utils/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,19 @@ func wrap(width int, s string) string {
return wordwrap.WrapString(s, uint(width))
}

// A string with n spaces
func indentStr(n int) string {
return strings.Repeat(" ", n)
}

// Indent a certain number of spaces
func indent(n int, s string) string {
return indentStr(n) + s
}

// Indent with spaces and also wrap
func indentWrap(indent int, width int, s string) string {
indentStr := strings.Repeat(" ", indent)
return indentStr + strings.ReplaceAll(wrap(width-indent, s), "\n", "\n"+indentStr)
func indentWrap(n int, width int, s string) string {
return indent(n, strings.ReplaceAll(wrap(width-n, s), "\n", "\n"+indentStr(n)))
}

// A way to assemble a map from keys and values in a template
Expand All @@ -148,8 +157,8 @@ func toMap(values ...interface{}) (map[string]interface{}, error) {
}

// Can make it easier to get the right number of line breaks
func nl() (string, error) {
return "\n", nil
func nl() string {
return "\n"
}

// For use in template.Funcs above
Expand All @@ -159,6 +168,7 @@ var templateHelpers = template.FuncMap{
"indicator": indicator,
"colorIndicator": colorIndicator,
"wrap": wrap,
"indent": indent,
"indentWrap": indentWrap,
"toMap": toMap,
"nl": nl,
Expand Down

0 comments on commit 0862dbe

Please sign in to comment.