gosubst

command module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 15, 2021 License: MIT Imports: 1 Imported by: 0

README

gosubst

gosubst is an envsubst on steroids. Receives a template file in the stdin replaces all variables and sends it to stdout.

Installing

Get the latest gosubst for your platform on the releases page

curl -o /usr/local/bin/gosubst -sSL https://github.com/luizbafilho/gosubst/releases/download/<version>/gosubst_<os>-<arch>
chmod +x /usr/local/bin/gosubst

Usage

gosubst copies the stdin to stdout replacing all variables.

gosubst copies stardard input to standard output replacing all variables present in values file

Usage:
  gosubst [flags]

Flags:
      --type string     values type (toml, yaml or json) (default "yaml")
  -v, --values string   values file

Values file sample:

foo: "bar"
baz:
 boo: "bla"
 zoo: "mee"

Template file sample:

Sample access: {{.foo}}
Accessing variables: {{.baz.boo}} | {{.baz.zoo}}
$ gosubst -f values.yaml < template.conf

Sample access: bar
Accessing variables: bla | mee
Values Files

The values file provides all the values to be replaced when the template is processed. gosubst supports yaml, json or toml files.

Environment variables

gosubst makes all environment variables available in the template.

$ echo "Home path: {{.Env.HOME}}" | gosubst
Home path: /home/vagrant
Template functions

Given that gosubst uses Go Templates you can leverage all the power Go provide. Here is a small sample:

{{with .Account -}}
Dear {{.FirstName}} {{.LastName}},  
{{- end}}

Below are your account statement details for period from {{.FromDate}} to {{.ToDate}}.

{{if .Purchases -}}
  Your purchases:
  {{- range .Purchases }}
      {{ .Date}} {{ printf "%-20s" .Description }} {{.AmountInCents -}}
  {{- end}}
{{- else}}
You didn't make any purchases during the period.  
{{- end}}

{{$note := .Account.Note -}}
{{if $note -}}
Note: {{$note}}  
{{- end}}

Best Wishes,  
Customer Service  

For more details: https://golang.org/pkg/text/template/#hdr-Text_and_spaces

Helper functions

gosubst makes available a lot of usefull functions provided by Sprig

$ echo "generated-id: {{uuidv4}}" | gosubst
generated-id: 00a315b7-c846-4751-b2ee-b50eb5359bac

$ echo "generated-sha: {{sha256sum .Env.USER | trunc 7}}" | gosubst
generated-sha: 4b569e8

Check it out all functions available: https://github.com/Masterminds/sprig#functions

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL