-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from patrickdappollonio/overhaul
Overhaul tgen: add support for Helm-like values file.
- Loading branch information
Showing
66 changed files
with
13,922 additions
and
951 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,59 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"errors" | ||
"io" | ||
"os" | ||
"text/template" | ||
) | ||
|
||
func command(w io.Writer, c conf) error { | ||
var b *bytes.Buffer | ||
|
||
if c.templateFile != "" { | ||
if c.rawTemplate != "" { | ||
return &conflictingArgsError{"file", "raw"} | ||
} | ||
|
||
if c.stdin { | ||
return &conflictingArgsError{"file", "stdin"} | ||
} | ||
|
||
bt, err := loadFile(c.templateFile) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
b = bt | ||
// You can't pass "--file" and "--execute" together | ||
if c.templateFilePath != "" && c.stdinTemplateFile != "" { | ||
return &conflictingArgsError{"file", "execute"} | ||
} | ||
|
||
if c.rawTemplate != "" { | ||
if c.templateFile != "" { | ||
return &conflictingArgsError{"raw", "file"} | ||
} | ||
|
||
if c.stdin { | ||
return &conflictingArgsError{"raw", "stdin"} | ||
} | ||
tg := &tgen{Strict: c.strictMode} | ||
|
||
b = bytes.NewBufferString(c.rawTemplate) | ||
// Read template from "-x" or "--execute" flag | ||
if c.stdinTemplateFile != "" { | ||
tg.setTemplate("-", c.stdinTemplateFile) | ||
} | ||
|
||
if c.stdin { | ||
if c.templateFile != "" { | ||
return &conflictingArgsError{"stdin", "file"} | ||
// Read template file (either from "--file" or stdin) | ||
if pathToOpen := c.templateFilePath; pathToOpen != "" { | ||
var err error | ||
switch pathToOpen { | ||
case "-": | ||
err = tg.loadTemplateFile("", os.Stdin) | ||
default: | ||
err = tg.loadTemplatePath(pathToOpen) | ||
} | ||
|
||
if c.rawTemplate != "" { | ||
return &conflictingArgsError{"stdin", "raw"} | ||
} | ||
|
||
bt, err := loadFile(os.Stdin.Name()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
b = bt | ||
} | ||
|
||
if b == nil { | ||
return errors.New("needs to specify either a template file (using --file) or a raw template (using --raw or --stdin)") | ||
// Set delimiters | ||
if c.customDelimiters != "" { | ||
if err := tg.setDelimiters(c.customDelimiters); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
envVars, err := loadVirtualEnv(c.environmentFile) | ||
if err != nil { | ||
return err | ||
// Load environment variable file | ||
if c.environmentFile != "" { | ||
if err := tg.loadEnvValues(c.environmentFile); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
c.t = template.New(appName).Funcs(getTemplateFunctions(envVars, c.strictMode)) | ||
|
||
if c.customDelimiters != "" { | ||
l, r, err := getDelimiter(c.customDelimiters) | ||
if err != nil { | ||
// Load yaml values file | ||
if c.valuesFile != "" { | ||
if err := tg.loadYAMLValues(c.valuesFile); err != nil { | ||
return err | ||
} | ||
|
||
c.t = c.t.Delims(l, r) | ||
} | ||
|
||
return executeTemplate(c.t, c.templateFile, w, envVars, b) | ||
// Render code | ||
return tg.render(w) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= | ||
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= | ||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= | ||
github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc= | ||
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= | ||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= | ||
github.com/spf13/cobra v1.5.0 h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU= | ||
github.com/spf13/cobra v1.5.0/go.mod h1:dWXEIy2H428czQCjInthrTRUg7yKbok+2Qi/yBIJoUM= | ||
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA= | ||
github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY= | ||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= | ||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= | ||
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= | ||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= | ||
golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg= | ||
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= | ||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.