sprig
sprig copied to clipboard
Suggestion: add function "autoindent"
When copying around templates that use indent or nindent, it's important to update the indentation as needed.
Suggestion: add function autoindent which calculates the indentation based on the indentation of the source line that the function was called from.
e.g. :
apiVersion: batch/v1
kind: Job
metadata:
name: {{ include "test-app-cli.fullname" . }}-{{ .Release.Revision }}
labels:
{{- include "test-app-cli.labels" . | nindent 4 }}
...
Could be converted to:
apiVersion: batch/v1
kind: Job
metadata:
name: {{ include "test-app-cli.fullname" . }}-{{ .Release.Revision }}
labels:
{{- include "test-app-cli.labels" . | autoindent }}
And autoindent will calculate the 4 automatically from the number of spaces on the source line.
An optional parameter will allow to add or subtract from the calculated indentation, default to 0 (zero).
I looked at the code of existing functions (e.g. https://github.com/Masterminds/sprig/blob/master/strings.go#L109) and haven't seen a way for them to access information such as the source line. Is this available somehow?