Skip to content

Commit 0862dbe

Browse files
authored
Merge pull request #1663 from simonbaird/text-output-image-ref-wrap-tweak
Don't wrap image ref in text output
2 parents bbdf3a4 + faba907 commit 0862dbe

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

internal/applicationsnapshot/templates/_results.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
{{- colorIndicator $type }} {{ colorText $type (printf "[%s] %s" $type .Metadata.code) }}{{ nl -}}
1717

1818
{{- if $imageRef -}}
19-
{{- indentWrap $indent $wrap (printf "ImageRef: %s" $imageRef ) }}{{ nl -}}
19+
{{- indent $indent (printf "ImageRef: %s" $imageRef ) }}{{ nl -}}
2020
{{- end -}}
2121

2222
{{/* For a success the message is generally just "Pass" so don't show it */}}

internal/utils/templates.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,19 @@ func wrap(width int, s string) string {
125125
return wordwrap.WrapString(s, uint(width))
126126
}
127127

128+
// A string with n spaces
129+
func indentStr(n int) string {
130+
return strings.Repeat(" ", n)
131+
}
132+
133+
// Indent a certain number of spaces
134+
func indent(n int, s string) string {
135+
return indentStr(n) + s
136+
}
137+
128138
// Indent with spaces and also wrap
129-
func indentWrap(indent int, width int, s string) string {
130-
indentStr := strings.Repeat(" ", indent)
131-
return indentStr + strings.ReplaceAll(wrap(width-indent, s), "\n", "\n"+indentStr)
139+
func indentWrap(n int, width int, s string) string {
140+
return indent(n, strings.ReplaceAll(wrap(width-n, s), "\n", "\n"+indentStr(n)))
132141
}
133142

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

150159
// Can make it easier to get the right number of line breaks
151-
func nl() (string, error) {
152-
return "\n", nil
160+
func nl() string {
161+
return "\n"
153162
}
154163

155164
// For use in template.Funcs above
@@ -159,6 +168,7 @@ var templateHelpers = template.FuncMap{
159168
"indicator": indicator,
160169
"colorIndicator": colorIndicator,
161170
"wrap": wrap,
171+
"indent": indent,
162172
"indentWrap": indentWrap,
163173
"toMap": toMap,
164174
"nl": nl,

0 commit comments

Comments
 (0)