func (s *Set) UnmarshalText(text []byte) error { lines := bufio.NewScanner(bytes.NewReader(text)) for lines.Scan() { words := bufio.NewScanner(bytes.NewReader(lines.Bytes())) words.Split(bufio.ScanWords) count := 0 dep := dependency.Dependency{} for words.Scan() { if strings.HasPrefix(words.Text(), "#") { break } if count == 0 { dep.Path = words.Text() } else if count == 1 { if words.Text() == "*" { dep.BleedingEdge = true } else { dep.Version = words.Text() } } else if count == 2 { dep.Tags = strings.Split(words.Text(), ",") } count++ } if count == 0 { // blank line continue } if count == 1 { return MissingVersionError{dep.Path} } // check for dupes for _, existing := range s.Dependencies { if strings.HasPrefix(dep.Path+"/", existing.Path+"/") { return DuplicateDependencyError{existing, dep} } if strings.HasPrefix(existing.Path+"/", dep.Path+"/") { return DuplicateDependencyError{existing, dep} } } s.Dependencies = append(s.Dependencies, dep) } return nil }