diff --git a/procfile.go b/procfile.go index 84d1601..599bbc3 100644 --- a/procfile.go +++ b/procfile.go @@ -1,17 +1,15 @@ package main import ( - "bytes" + "bufio" + "fmt" "github.com/kr/pretty" "io" - "io/ioutil" "os" "regexp" ) -const ( - procfileEntryRegexp = "^([A-Za-z0-9_]+):\\s*(.+)$" -) +var procfileEntryRegexp = regexp.MustCompile("^([A-Za-z0-9_]+):\\s*(.+)$") type ProcfileEntry struct { name string @@ -24,7 +22,7 @@ type Procfile struct { var _ = pretty.Println // lol -func OpenProcfile(filename string) (*Procfile, error) { +func ReadProcfile(filename string) (*Procfile, error) { fd, err := os.Open(filename) if err != nil { return nil, err @@ -35,17 +33,13 @@ func OpenProcfile(filename string) (*Procfile, error) { func parseProcfile(r io.Reader) (*Procfile, error) { pf := new(Procfile) - b, err := ioutil.ReadAll(r) - if err != nil { - return nil, err + scanner := bufio.NewScanner(r) + for scanner.Scan() { + parts := procfileEntryRegexp.FindStringSubmatch(scanner.Text()) + pf.entries = append(pf.entries, ProcfileEntry{parts[1], parts[2]}) } - lines := bytes.Split(b, []byte("\n")) - for _, line := range lines { - r := regexp.MustCompile(procfileEntryRegexp) - parts := r.FindStringSubmatch(string(line)) - if parts != nil { - pf.entries = append(pf.entries, ProcfileEntry{parts[1], parts[2]}) - } + if err := scanner.Err(); err != nil { + return nil, fmt.Errorf("Reading Procfile: %s", err) } return pf, nil } diff --git a/start.go b/start.go index 41a973b..d467124 100644 --- a/start.go +++ b/start.go @@ -28,7 +28,7 @@ func init() { } func runStart(cmd *Command, args []string) { - pf, err := OpenProcfile(flagProcfile) + pf, err := ReadProcfile(flagProcfile) if err != nil { fmt.Println("ERROR:", err) return