EnvP is a simple CLI util that passes your file through golang/Template with your environment, allowing you to do more advanced configurations in things like Docker without very much effort. It also provides several helpers that will aid in this task, and make your life generally easy.
Flag | Type | Description | Repeatable (Array) |
---|---|---|---|
--write-to | string | the file to write to | false |
--file | string | the file, or dir | true |
Leaving --file
empty will print the final result to stdout, this is really meant for testing before you make commits but can be used any way you wish. As well, if you set --file
to a directory, it will glob for .gohtml
(even if it's gotxt)
{{ split [string] [delim] }}
{{ myStr := "1,2,3" }}
{{ range $_, $e := (split $myStr ",") }}
{{ $e }}
{{ end }}
{{ chomp [string] [cutset] }}
{{ myStr := "hello" }}
{{ chomp $myStr "o" }}
Strips indentation to the edge at the smallest length, and reindents to the specified length.
{{ indent [string] [n] }}
{{ define "myTemplate" }}
hello {
world
}
{{ end }}
{{ str := templateString "myTemplate" }}
{{ indent $str 6 }}
hello {
world
}
Add space to the beginning of a string
{{ addSpace [string] [int] }}
Get a template as a string that can be manipulated
{{ templateString [template] }}
{{ define "myTemplate" }}
hello {
world
}
{{ end }}
{{ $template := (templateString "myTemplate") }}
{{ indent $template 8 }}
Strips lines of empty space, and removes all edge space.
{{ strippedTemplate [template] }}
{{ define "myTemplate" }}
hello {
world
}
{{ end }}
{{ strippedTemplate "myTemplate" }}
hello {
world
}
Strips lines of empty space, and removes all edge space.
{{ strip [string] }}
{{ define "myTemplate" }}
hello {
world
}
{{ end }}
{{ $myVar := (templateString "myTemplate" }}
{{ strip $myVar }}
hello {
world
}
Strips indentation to the edge like String#strip_heredoc
or <<~STR
in Ruby.
{{ fixIndentedTemplate [template] }}
{{ define "myTemplate" }}
hello {
world
}
{{ end }}
{{ fixIndentedTemplate "myTemplate" }}
hello {
world
}
Allows you to perform booleans on a template
{{ templateExists [template] }}
{{ if (templateExists "myTemplate") }}
{{ template "myTemplate" }}
{{ end }}
Strips indentation to the edge like String#strip_heredoc or <<~STR in Ruby.
{{ fixIndentation [string] }}
{{ define "myTemplate" }}
hello {
world
}
{{ end }}
{{ myVar := (templateString "myTemplate") }}
{{ fixIndentation $myVar }}
hello {
world
}
Lets you check if an environment variable exists.
{{ envExists [key] }}
{{ if (envExists "key") }}
Do Work
{{ end }}
Extracts an environment variable as a boolean.
{{ boolEnv [key] }}
{{ if (boolEnv "key") }}
Do Work
{{ end }}
Extracts an environment variable as a string.
{{ env [key] }}
Generate an alphanumeric password using cryptographically derived random numbers.
{{ randomPassword [length] }}
Given you did
export GHOST_PORT=8080
export GHOST_ENV=production
export [email protected]
export CADDY_TLS=true
envp \
-prefix=ghost \
-file=ghost.gohtml \
-stdout
And ghost.gohtml
was
{{- define "hostnames" -}}
{{- if eq (env "ghost_env") "development" -}}
http://localhost
{{- else -}}
{{ $g := env "ghost_hostname" }}
{{- if boolEnv "caddy_tls" -}}
http://{{$g}} https://{{$g}}
{{- else -}}
http://{{$g}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- define "tls" -}}
{{- if and (ne (env "ghost_env") "development") (boolEnv "caddy_tls") -}}
tls {{ env "caddy_tls_email" }}
{{- end -}}
{{- end -}}
{{ template "tls" }}
{{ template "hostnames" }}
root /srv/caddy/ghost
ext .html .htm
{{ if and (envExists "ghost_port") (ne (env "ghost_port") "") }}
proxy localhost:{{ env "ghost_port" }} {
transparent
websocket
}
{{ end }}
You would get
tls [email protected]
http://example.com
root /srv/caddy/ghost
ext .html .htm
proxy localhost:8080 {
transparent
websocket
}