func (d *Dockerfile) PrependLine(line string) error {
	node, err := ParseLine(line)
	if err != nil {
		return err
	}
	return d.PrependNode(node)
}
PrependLine parses and prepends a new line to the AST
package dockerpatch
import (
	"bytes"
	"fmt"
	"io"
	"strings"
	"github.com/docker/docker/builder/dockerfile/command"
	"github.com/docker/docker/builder/dockerfile/parser"
)
type Dockerfile struct {
	root *parser.Node
}
func DockerfileNew() *Dockerfile {
	dockerfile, _ := DockerfileFromString("")
	return dockerfile
}
func DockerfileFromString(input string) (*Dockerfile, error) {
	payload := new(bytes.Buffer)
	payload.Write([]byte(input))
	return DockerfileRead(payload)
}
func DockerfileRead(input io.Reader) (*Dockerfile, error) {
	dockerfile := Dockerfile{}
	d := parser.Directive{LookingForDirectives: true}
	parser.SetEscapeToken(parser.DefaultEscapeToken, &d)
	root, err := parser.Parse(input, &d)
	if err != nil {
		return nil, err
	}
	dockerfile.root = root
	return &dockerfile, nil
}
func (d *Dockerfile) RemoveAt(i int) error {
	if i >= 0 && i < d.Length() {
		d.root.Children = append(d.root.Children[:i], d.root.Children[i+1:]...)
		return nil
	}
	return fmt.Errorf("Cannot remove %d: index error", i)
}
func (d *Dockerfile) String() string {
	lines := []string{}
	for _, child := range d.root.Children {
		lines = append(lines, child.Original)
	}
	return strings.Join(lines, "\n")
}
func (d *Dockerfile) PrependNode(node *parser.Node) error {
	d.root.Children = append([]*parser.Node{node}, d.root.Children...)
	return nil
}
func (d *Dockerfile) AppendNode(node *parser.Node) error {
	d.root.Children = append(d.root.Children, node)
	return nil
}
func (d *Dockerfile) RemoveNodesByType(nodeType string) error {
	newChildren := []*parser.Node{}
	for _, node := range d.root.Children {
		if node.Value != nodeType {
			newChildren = append(newChildren, node)
		}
	}
	d.root.Children = newChildren
	return nil
}
func (d *Dockerfile) SetFrom(from string) error {
	if err := d.RemoveNodesByType(command.From); err != nil {
		return err
	}
	return d.PrependLine(fmt.Sprintf("FROM %s", from))
}
func ParseLine(line string) (*parser.Node, error) {
	tmp, err := DockerfileFromString(line)
	if err != nil {
		return nil, err
	}
	return tmp.root.Children[0], nil
}
func (d *Dockerfile) From() string {
	for _, node := range d.root.Children {
		if node.Value == command.From {
			return strings.Split(node.Original, " ")[1]
		}
	}
	return ""
}
func (d *Dockerfile) Length() int {
	return len(d.root.Children)
}
func (d *Dockerfile) AppendLine(line string) error {
	node, err := ParseLine(line)
	if err != nil {
		return err
	}
	return d.AppendNode(node)
}