shared/generate/file/write.go
func Append(path string, snippet Snippet) error {
	buffer := newBuffer()
	buffer.N()

	err := snippet.Generate(buffer)
	if err != nil {
		return errors.Wrap(err, "Generate code snippet")
	}

	var file *os.File

	if path == "-" {
		file = os.Stdout
	} else {
		file, err = os.OpenFile(path, os.O_APPEND|os.O_WRONLY, 0644)
		if err != nil {
			return errors.Wrapf(err, "Open target source code file '%s'", path)
		}
		defer file.Close()
	}

	bytes, err := buffer.code()
	if err != nil {
		return err
	}

	_, err = file.Write(bytes)
	if err != nil {
		return errors.Wrapf(err, "Append snippet to target source code file '%s'", path)
	}

	return nil
}
func Append(path string, snippet Snippet) error {
	buffer := newBuffer()
	buffer.N()

	err := snippet.Generate(buffer)
	if err != nil {
		return errors.Wrap(err, "Generate code snippet")
	}

	var file *os.File

	if path == "-" {
		file = os.Stdout
	} else {
		file, err = os.OpenFile(path, os.O_APPEND|os.O_WRONLY, 0644)
		if err != nil {
			return errors.Wrapf(err, "Open target source code file '%s'", path)
		}
		defer file.Close()
	}

	bytes, err := buffer.code()
	if err != nil {
		return err
	}

	_, err = file.Write(bytes)
	if err != nil {
		return errors.Wrapf(err, "Append snippet to target source code file '%s'", path)
	}

	return nil
}
// Append a code snippet to a file.