Reject options that cannot take effect, and skip entries that are not data

This commit is contained in:
M
2026-08-28 00:17:39 +02:00
committed by lilleman-tw
parent 8d0393713c
commit b14caae3a8
4 changed files with 63 additions and 6 deletions
+12 -2
View File
@@ -53,6 +53,9 @@ func loadDir(dir string) (*group, error) {
}
g := &group{children: map[string]node{}}
for _, e := range entries {
if strings.HasPrefix(e.Name(), ".") { // hidden: a checkout or an editor's file, never data
continue
}
full := filepath.Join(dir, e.Name())
if e.IsDir() {
if isRef(e.Name()) {
@@ -62,9 +65,13 @@ func loadDir(dir string) (*group, error) {
if err != nil {
return nil, err
}
if len(child.children) > 0 {
g.children[e.Name()] = child
if len(child.children) == 0 {
continue
}
if err := checkName(e.Name()); err != nil {
return nil, fmt.Errorf("%s: folder %w", full, err)
}
g.children[e.Name()] = child
continue
}
if !strings.HasSuffix(e.Name(), ".json") {
@@ -74,6 +81,9 @@ func loadDir(dir string) (*group, error) {
if isRef(name) {
return nil, fmt.Errorf("%s: category %q starts with %q, which is reserved for {..path} bindings", full, name, refPrefix)
}
if err := checkName(name); err != nil {
return nil, fmt.Errorf("%s: category %w", full, err)
}
b, err := os.ReadFile(full)
if err != nil {
return nil, err