parsePaths is the internal entrypoint for parsing a list of paths. It assumes that the caller has already checked that the paths exist. It also assumes that the caller has already removed any previous resources related to the paths, enabling parsePaths to insert changed resources without conflicts.
(ctx context.Context, paths []string)
| 603 | // It also assumes that the caller has already removed any previous resources related to the paths, |
| 604 | // enabling parsePaths to insert changed resources without conflicts. |
| 605 | func (p *Parser) parsePaths(ctx context.Context, paths []string) error { |
| 606 | // Check limits |
| 607 | if len(paths) > maxFiles { |
| 608 | return fmt.Errorf("project exceeds file limit of %d", maxFiles) |
| 609 | } |
| 610 | |
| 611 | // Sort paths such that a) we always parse rill.yaml first (to pick up defaults), |
| 612 | // and b) we align files with the same name but different extensions next to each other. |
| 613 | slices.SortFunc(paths, func(a, b string) int { |
| 614 | if pathIsRillYAML(a) { |
| 615 | return -1 |
| 616 | } |
| 617 | if pathIsRillYAML(b) { |
| 618 | return 1 |
| 619 | } |
| 620 | return strings.Compare(a, b) |
| 621 | }) |
| 622 | |
| 623 | // Iterate over the sorted paths, processing all paths with the same stem at once (stem = path without extension). |
| 624 | sawRillYAML := false |
| 625 | for i := 0; i < len(paths); { |
| 626 | // Handle rill.yaml and .env separately |
| 627 | path := paths[i] |
| 628 | if pathIsRillYAML(path) { |
| 629 | err := p.parseRillYAML(ctx, path) |
| 630 | if err != nil { |
| 631 | p.addParseError(path, err, false) |
| 632 | } |
| 633 | sawRillYAML = true |
| 634 | i++ |
| 635 | continue |
| 636 | } else if pathIsDotEnv(path) { |
| 637 | err := p.parseDotEnv(ctx, path) |
| 638 | if err != nil { |
| 639 | p.addParseError(path, err, false) |
| 640 | } |
| 641 | i++ |
| 642 | continue |
| 643 | } |
| 644 | |
| 645 | // Identify the range of paths with the same stem as paths[i] |
| 646 | j := i + 1 |
| 647 | pathStemI := pathStem(paths[i]) |
| 648 | for j < len(paths) && pathStemI == pathStem(paths[j]) { |
| 649 | j++ |
| 650 | } |
| 651 | |
| 652 | // Parse the paths with the same stem |
| 653 | err := p.parseStemPaths(ctx, paths[i:j]) |
| 654 | if err != nil { |
| 655 | return err |
| 656 | } |
| 657 | |
| 658 | // Advance i to the next stem |
| 659 | i = j |
| 660 | } |
| 661 | |
| 662 | // If we didn't encounter rill.yaml (in this run or a previous run), that's a breaking error |
no test coverage detected