func tplPaths(ska, tpl string) (vp, tp string) {
	tplf := fmt.Sprintf("%s/%s", ska, tpl)
	return fmt.Sprintf("%s/values.toml", tplf), fmt.Sprintf("%s/templates", tplf)
}
tplPaths returns values.toml path (vp) and templates dir path (tp).
package main
import (
	"bufio"
	"bytes"
	"fmt"
	"html/template"
	"io"
	"io/ioutil"
	"log"
	"os"
	"os/exec"
	"path/filepath"
	"runtime"
	"strings"
	"github.com/BurntSushi/toml"
	"github.com/Masterminds/sprig"
	"github.com/google/shlex"
	"github.com/spf13/cobra"
)
func main() {
	log.SetFlags(0)
	cmd := &cobra.Command{
		Use:   "ska [template]",
		Short: "Render template",
		Args:  cobra.ExactArgs(1),
		Run:   run,
	}
	setUpFlags(cmd)
	must(cmd.Execute())
}
func setUpFlags(cmd *cobra.Command) {
	cmd.PersistentFlags().StringP("templates", "t", templatePathDefault(), "templates dir")
	cmd.PersistentFlags().StringP("output", "o", ".", "output")
	cmd.PersistentFlags().StringP("editor", "e", os.Getenv("EDITOR"), "editor")
	cmd.PersistentFlags().StringP("values", "v", "", "values path")
	cmd.PersistentFlags().BoolP("default-values", "d", false, "use default values")
}
func run(cmd *cobra.Command, args []string) {
	var (
		ska                = cmd.Flag("templates").Value.String()
		out                = cmd.Flag("output").Value.String()
		editor             = cmd.Flag("editor").Value.String()
		externalValuesPath = cmd.Flag("values").Value.String()
		defaultValues      = cmd.Flag("default-values").Value.String()
	)
	valuePath, templatesPath := tplPaths(ska, args[0])
	out, err := filepath.Abs(out)
	if err != nil {
		must(err)
	}
	var values map[string]interface{}
	switch {
	case defaultValues == "true":
		values = readValuesFromPath(valuePath)
	case externalValuesPath != "":
		values = readValuesFromPath(externalValuesPath)
	default:
		values = readValuesFromTempFile(valuePath, editor)
	}
	if err != nil && !os.IsNotExist(err) {
		must(err)
	}
	must(walk(templatesPath, out, values, gen))
}
func readValuesFromPath(valuePath string) map[string]interface{} {
	valuePath, _ = filepath.Abs(valuePath)
	values, err := vals(valuePath)
	if err != nil {
		log.Fatalf("Error while parsing default values: %v", err)
	}
	return values
}
func readValuesFromTempFile(valuePath, editor string) map[string]interface{} {
	tmp, err := tempfile(valuePath)
	if err != nil {
		log.Fatalf("Error while creating temp value file: %v", err)
	}
	s := bufio.NewScanner(os.Stdin)
	var values map[string]interface{}
	for {
		must(invokeEditor(editor, tmp))
		var err error
		values, err = vals(tmp)
		if !(err != nil) {
			break
		}
		fmt.Printf("Error while parsing file: %v\n", err)
		s.Scan()
	}
	if err := os.RemoveAll(tmp); err != nil {
		fmt.Fprintf(os.Stderr, "%v", err)
	}
	return values
}