2020-09-08 17:49:02 -06:00
|
|
|
package transpile
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"sort"
|
|
|
|
|
|
|
|
"github.com/spf13/afero"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Inventory maps category names to lists of point values.
|
|
|
|
type Inventory map[string][]int
|
|
|
|
|
|
|
|
// FsInventory returns a mapping of category names to puzzle point values.
|
|
|
|
func FsInventory(fs afero.Fs) (Inventory, error) {
|
2020-09-11 13:03:19 -06:00
|
|
|
dirEnts, err := afero.ReadDir(fs, "")
|
2020-09-08 17:49:02 -06:00
|
|
|
if err != nil {
|
|
|
|
log.Print(err)
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
inv := make(Inventory)
|
|
|
|
for _, ent := range dirEnts {
|
|
|
|
if ent.IsDir() {
|
|
|
|
name := ent.Name()
|
|
|
|
c := NewFsCategory(fs, name)
|
|
|
|
puzzles, err := c.Inventory()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
sort.Ints(puzzles)
|
|
|
|
inv[name] = puzzles
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return inv, nil
|
|
|
|
}
|