package main

import (
	"log"
	"os"
)

func check_main(args []string) {
	allCarr, err := allCarriersWithErrors()
	if err != nil {
		log.Fatalf("Unable to open library: %s", err)
	}

	exitStatus := 0

	for _, pc := range allCarr {
		if pc.Error != nil {
			exitStatus = 1
			log.Printf("Parse error in %s: %s", pc.Filename, pc.Error)
			continue
		}

		if pc.Carrier.ID == "" {
			exitStatus = 1
			log.Printf("%s: no carrier ID", pc.Filename)
		}
	}

	os.Exit(exitStatus)
}

package main

import (
	"fmt"
	"log"
	"os"
	"path"

	"github.com/thijzert/speeldoos"
	"github.com/thijzert/speeldoos/lib/zipmap"
)

type checkF func(*speeldoos.Carrier) []error

var allChecks []checkF = []checkF{
	check_carrierID,
	check_sourceFiles,
}

func check_main(args []string) {
	allCarr, err := allCarriersWithErrors()
	if err != nil {
		log.Fatalf("Unable to open library: %s", err)
	}

	exitStatus := 0

	for _, pc := range allCarr {
		if pc.Error != nil {
			exitStatus = 1
			log.Printf("Parse error in %s: %s", pc.Filename, pc.Error)
			continue
		}

		for _, f := range allChecks {
			errs := f(pc.Carrier)
			if errs != nil {
				for _, e := range errs {
					exitStatus = 1
					log.Printf("%s: %s", pc.Filename, e.Error())
				}
			}
		}
	}

	os.Exit(exitStatus)
}

func check_carrierID(foo *speeldoos.Carrier) []error {
	if foo.ID == "" {
		return []error{fmt.Errorf("no carrier ID")}
	}
	return nil
}

func check_sourceFiles(foo *speeldoos.Carrier) []error {
	rv := []error{}

	zm := zipmap.New()

	for _, perf := range foo.Performances {
		for _, sf := range perf.SourceFiles {
			if !zm.Exists(path.Join(Config.LibraryDir, sf.Filename)) {
				rv = append(rv, fmt.Errorf("source file missing: %s", sf))
			}
		}
	}

	return rv
}

Check if every source file exists
Check if every source file exists
