cmd

package
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RootCmd = &cobra.Command{
	Use:   "envtpl",
	Short: "Render go templates from environment variables",
	Long:  `Render go templates from environment variables.`,
	Run: func(cmd *cobra.Command, args []string) {
		// load template; if an argument is not specified, default to stdin
		var t *template.Template
		if len(args) > 0 {
			t, err = parseFiles(args...)
			checkError(err)
		} else {
			bytes, err := ioutil.ReadAll(os.Stdin)
			checkError(err)
			t, err = parse(string(bytes))
			checkError(err)
		}

		env := readEnv()

		// get writer for rendered output; if an output file is not
		// specified, default to stdout
		var w io.Writer
		if len(output) > 0 {
			f, err := os.Create(output)
			checkError(err)
			defer f.Close()
			w = io.Writer(f)
		} else {
			w = os.Stdout
		}

		err := t.Execute(w, env)
		checkError(err)
	},
}

Functions

func Execute

func Execute()

Types

This section is empty.

Jump to

Keyboard shortcuts

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