From f77fc4ef5f2df96c6bba3cd6c7d88a77d61a5a80 Mon Sep 17 00:00:00 2001 From: ewy Date: Tue, 2 Jun 2026 15:07:59 +0200 Subject: add .wants and .includes .wants adds potential out-of-tree sources to your state (for monorepos, for example) .includes adds targets from another source to this one, adding inheritance --- indexers/pikdex/hydrate.go | 2 +- indexers/pikdex/hydrate_test.go | 3 ++- indexers/pikdex/index.go | 26 +++++++++----------------- indexers/pikdex/meta.go | 21 ++++++++++++++------- 4 files changed, 26 insertions(+), 26 deletions(-) (limited to 'indexers') diff --git a/indexers/pikdex/hydrate.go b/indexers/pikdex/hydrate.go index 1f71992..a0dfc2b 100644 --- a/indexers/pikdex/hydrate.go +++ b/indexers/pikdex/hydrate.go @@ -6,7 +6,7 @@ import ( ) func (u *pikdex) Mod(src *model.Source, result *model.HydratedSource) error { - mod := u.mods[strings.TrimSuffix(src.Path, "/")] + mod := u.Data[strings.TrimSuffix(src.Path, "/")] if mod.Path != "" { if mod.Aliases != nil { result.Aliases = append(result.Aliases, mod.Aliases...) diff --git a/indexers/pikdex/hydrate_test.go b/indexers/pikdex/hydrate_test.go index ba5e1bc..cd2433a 100644 --- a/indexers/pikdex/hydrate_test.go +++ b/indexers/pikdex/hydrate_test.go @@ -3,6 +3,7 @@ package pikdex import ( + "github.com/ewy1/pik/model" "github.com/ewy1/pik/runner" "github.com/stretchr/testify/assert" "testing" @@ -11,7 +12,7 @@ import ( func TestHydrate(t *testing.T) { aliases := []string{"alias1", "alias2"} p := pikdex{ - mods: map[string]*SourceData{ + Data: map[string]*model.SourceData{ "asdf": { Aliases: aliases, Icon: "I", diff --git a/indexers/pikdex/index.go b/indexers/pikdex/index.go index 1a9b38a..15a74f4 100644 --- a/indexers/pikdex/index.go +++ b/indexers/pikdex/index.go @@ -35,19 +35,11 @@ func (u *pikdex) Init() error { return nil } -var Indexer = &pikdex{mods: make(map[string]*SourceData)} +var Indexer = &pikdex{Data: make(map[string]*model.SourceData)} type pikdex struct { sync.Mutex - mods map[string]*SourceData -} - -type SourceData struct { - Aliases []string - Icon string - Path string - Wants []string - Includes []string + Data map[string]*model.SourceData } func (u *pikdex) Index(absPath string, f fs.FS, runners []model.Runner) ([]model.Target, error) { @@ -57,14 +49,14 @@ func (u *pikdex) Index(absPath string, f fs.FS, runners []model.Runner) ([]model } var targets []model.Target u.Lock() - mod := u.mods[absPath] + mod := u.Data[absPath] u.Unlock() if mod == nil { u.Lock() - u.mods[absPath] = &SourceData{ + u.Data[absPath] = &model.SourceData{ Path: absPath, } - mod = u.mods[absPath] + mod = u.Data[absPath] u.Unlock() } err = fs.WalkDir(f, root, func(p string, d fs.DirEntry, err error) error { @@ -99,12 +91,12 @@ func (u *pikdex) Index(absPath string, f fs.FS, runners []model.Runner) ([]model for _, r := range runners { wants, err := r.Wants(f, p, d) if err != nil { - spool.Warn("%v\n", err) + _, _ = spool.Warn("%v\n", err) } if wants { t, err := r.CreateTarget(f, absPath, p, d) if err != nil { - spool.Warn("%v\n", err) + _, _ = spool.Warn("%v\n", err) } sub := t.Sub() if strings.Join(sub, " ") == t.ShortestId() { @@ -123,13 +115,13 @@ func (u *pikdex) Index(absPath string, f fs.FS, runners []model.Runner) ([]model return nil } if err != nil { - spool.Warn("%v\n", err) + _, _ = spool.Warn("%v\n", err) } } return nil }) u.Lock() - u.mods[absPath] = mod + u.Data[absPath] = mod u.Unlock() return targets, err diff --git a/indexers/pikdex/meta.go b/indexers/pikdex/meta.go index ef2c029..69b3f92 100644 --- a/indexers/pikdex/meta.go +++ b/indexers/pikdex/meta.go @@ -3,22 +3,29 @@ package pikdex import ( "github.com/charmbracelet/lipgloss" "github.com/ewy1/pik/describe" + "github.com/ewy1/pik/model" "strings" ) -type MetaSetter func(s *SourceData, content string) +type MetaSetter func(s *model.SourceData, content string) var MetaFiles = map[string]MetaSetter{ - ".wants": func(s *SourceData, content string) { - s.Wants = contentLines(content) + ".want": func(s *model.SourceData, content string) { + s.Wants = append(s.Wants, contentLines(content)...) }, - ".includes": func(s *SourceData, content string) { - s.Includes = contentLines(content) + ".wants": func(s *model.SourceData, content string) { + s.Wants = append(s.Wants, contentLines(content)...) }, - ".alias": func(s *SourceData, content string) { + ".include": func(s *model.SourceData, content string) { + s.Includes = append(s.Includes, contentLines(content)...) + }, + ".includes": func(s *model.SourceData, content string) { + s.Includes = append(s.Includes, contentLines(content)...) + }, + ".alias": func(s *model.SourceData, content string) { s.Aliases = contentLines(content) }, - ".icon": func(s *SourceData, content string) { + ".icon": func(s *model.SourceData, content string) { lines := contentLines(content) if len(lines) == 0 { return -- cgit v1.3.1