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))
}
SetFrom sets the current FROM
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
}