Esempio n. 1
0
func main() {
	flag.Parse()
	if *version {
		fmt.Println(Version)
		os.Exit(0)
	}
	if *posix {
		sigil.PosixPreprocess = true
	}
	if os.Getenv("SIGIL_PATH") != "" {
		sigil.TemplatePath = strings.Split(os.Getenv("SIGIL_PATH"), ":")
	}
	vars := make(map[string]string)
	for _, arg := range flag.Args() {
		parts := strings.SplitN(arg, "=", 2)
		if len(parts) == 2 {
			vars[parts[0]] = parts[1]
		}
	}
	tmpl, name, err := template()
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
	render, err := sigil.Execute(tmpl, vars, name)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
	os.Stdout.Write(render.Bytes())
}
Esempio n. 2
0
func load(name string) {
	data, err := ioutil.ReadFile(name + ".yml")
	fatal(err)
	rendered, err := sigil.Execute(data, config, name)
	fatal(err)
	var service map[string]interface{}
	fatal(yaml.Unmarshal(rendered.Bytes(), &service))
	if value, ok := service["extra"]; ok {
		exports := value.(map[interface{}]interface{})
		for k, v := range exports {
			config[k.(string)] = v
		}
		delete(service, "extra")
	}
	services[name] = service
}
Esempio n. 3
0
func Run(config *entrykit.Config) {
	defer entrykit.Exec(config.Exec)
	for name, target := range config.Tasks {
		template := target + ".tmpl"
		data, err := ioutil.ReadFile(template)
		if err != nil {
			entrykit.Error(err)
		}
		render, err := sigil.Execute(data, nil, name)
		if err != nil {
			entrykit.Error(err)
		}
		// todo: use same filemode as template
		err = ioutil.WriteFile(target, render.Bytes(), 0644)
		if err != nil {
			entrykit.Error(err)
		}
	}
}
Esempio n. 4
0
func render(data []byte, args []interface{}, name string) (bytes.Buffer, error) {
	vars := make(map[string]string)
	for _, arg := range args {
		mv, ok := arg.(map[string]string)
		if ok {
			for k, v := range mv {
				vars[k] = v
			}
			continue
		}
		sv, ok := arg.(string)
		if !ok {
			continue
		}
		parts := strings.SplitN(sv, "=", 2)
		if len(parts) == 2 {
			vars[parts[0]] = parts[1]
		}
	}
	return sigil.Execute(data, vars, name)
}