Beispiel #1
0
// Render is helper to render the config file to the output.
func (c *Config) Render() {
	if c.f.Root == nil {
		fmt.Println(nil)
		return
	}
	fmt.Println(yaml.Render(c.f.Root))
}
Beispiel #2
0
// WriteYaml writes a yaml.Node to the console as a string.
//
// Params:
//	- yaml.Node (yaml.Node): A yaml.Node to render.
// 	- out (io.Writer): An output stream to write to. Default is os.Stdout.
// 	- filename (string): If set, the file will be opened and the content will be written to it.
func WriteYaml(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
	top := p.Get("yaml.Node", yaml.Scalar("nothing to print")).(yaml.Node)
	toStdout := p.Get("toStdout", true).(bool)
	var out io.Writer
	if nn, ok := p.Has("filename"); ok && len(nn.(string)) > 0 {
		file, err := os.Create(nn.(string))
		if err != nil {
		}
		defer file.Close()
		out = io.Writer(file)
		fmt.Fprint(out, yaml.Render(top))
	} else if toStdout {
		out = p.Get("out", os.Stdout).(io.Writer)
		fmt.Fprint(out, yaml.Render(top))
	}
	// Otherwise we supress output.

	return true, nil
}
Beispiel #3
0
func quickDirtyYAMLWrite(dir string, d []*Dependency, pkg string) error {
	if len(d) == 0 {
		return nil
	}
	c := &Config{Name: pkg, Imports: d}
	node := c.ToYaml()
	data := yaml.Render(node)
	f := path.Join(dir, "glide.yaml")
	Info("Writing new glide.yaml file in %s\n", dir)
	return ioutil.WriteFile(f, []byte(data), 0755)
}
Beispiel #4
0
func TestYamlRender(t *testing.T) {
	const EXPECTED = "Hello: World\n"
	a.Equal(t, yaml.Render(yamlDoc), EXPECTED, "incorrect rendering!")
}
Beispiel #5
0
func main() {
	fmt.Printf("%s\n", yaml.Render(yamlDoc))
}