nix-amer/internal/buildfile/reader.go

50 lines
936 B
Go

package buildfile
import (
"bufio"
"git.xdrm.io/xdrm-brackets/nix-amer/internal/instruction"
"io"
)
// Reader is the buildfile reader
type Reader struct {
// linux distribution to run on
distribution string
Content []instruction.T
}
// NewReader creates a new reader for the specified build file and linux distribution
func NewReader(distro string, buildfile io.Reader) (*Reader, error) {
r := &Reader{
distribution: distro,
Content: make([]instruction.T, 0),
}
// add each line as instruction
l, reader := 0, bufio.NewReader(buildfile)
for {
l++
// read line until end
line, err := reader.ReadString('\n')
if err == io.EOF {
break
} else if err != nil {
return nil, LineError{l, err}
}
// turn into instruction
inst, err := instruction.Parse(line)
if err != nil {
return nil, LineError{l, err}
}
// add to list
r.Content = append(r.Content, inst)
}
return r, nil
}