func loadKeyValues(keys []string) (map[string]string, error) {
	keyValues := make(map[string]string)
	for _, key := range keys {
		if value := os.Getenv(key); value == "" {
			return nil, errors.New(fmt.Sprintf("Environment variable [%s] not found", key))
		} else {
			keyValues[key] = value
		}
	}
	return keyValues, nil
}
loadKeyValues loads all values for the keys specified via the command-line flag
package main
import (
	"bufio"
	"bytes"
	"errors"
	"fmt"
	"github.com/alecthomas/kingpin"
	"io/ioutil"
	"log"
	"os"
	"strings"
)
var (
	keyNames = kingpin.Flag("keys", "Comma-delimited list of keys to be replaced by their respective environment variable value.").Required().String()
	output   = kingpin.Flag("output", "Output file name. default srcdir/source.go").String()
	paths    = kingpin.Arg("paths", "directories or files").Strings()
)
type errWriter struct {
	b   *bytes.Buffer
	err error
}
func (ew *errWriter) writeString(value string) {
	if ew.err != nil {
		return
	}
	_, ew.err = ew.b.WriteString(value)
}
func main() {
	kingpin.Version("1.0.0")
	kingpin.Parse()
	if err := run(*keyNames, *output, *paths); err != nil {
		log.Fatal(err)
	}
}
func run(keys string, out string, inputPaths []string) error {
	k := strings.Split(keys, ",")
	keyValues, err := loadKeyValues(k)
	if err != nil {
		return err
	}
	if len(inputPaths) == 1 && isFile(inputPaths[0]) {
		var buffer bytes.Buffer
		if err := writeHeader(&buffer, k, out); err != nil {
			return err
		}
		src, err := substituteValues(inputPaths[0], keyValues, &buffer)
		if err != nil {
			return err
		}
		if out == "" {
			out = inputPaths[0]
		}
		err = ioutil.WriteFile(out, src, 0644)
		if err != nil {
			return err
		}
	} else {
		return errors.New("Only single file inputs are currently supported")
	}
	return nil
}