diff options
Diffstat (limited to 'runner/base.go')
| -rw-r--r-- | runner/base.go | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/runner/base.go b/runner/base.go index c9825ae..e1fef66 100644 --- a/runner/base.go +++ b/runner/base.go @@ -1,15 +1,35 @@ package runner import ( + "path/filepath" "pik/identity" + "pik/indexers/pikdex" "pik/model" + "slices" + "strings" ) // BaseTarget is an embeddable type which contains some of the information we need for (almost) every target. type BaseTarget struct { identity.Identity MyTags model.Tags - Sub []string + MySub []string +} + +func SubFromFile(file string) []string { + _, filename := filepath.Split(file) + var sub []string + split := strings.Split(file, "/") + for _, p := range split { + if slices.Contains(pikdex.Roots, p) { + continue + } + if filename == p { + continue + } + sub = append(sub, p) + } + return sub } func (t *BaseTarget) Tags() model.Tags { @@ -29,7 +49,7 @@ func (b *BaseTarget) Visible() bool { } func (b *BaseTarget) Invocation(src *model.Source) []string { - return append([]string{src.Identity.Reduced}, append(b.Sub, b.Identity.Reduced)...) + return append([]string{src.Identity.Reduced}, append(b.MySub, b.Identity.Reduced)...) } func Hydrated[T model.Target](in T) BaseHydration[T] { @@ -53,3 +73,7 @@ func (b *BaseHydration[T]) Description() string { func (b *BaseHydration[T]) Target() model.Target { return b.Self } + +func (b *BaseTarget) Sub() []string { + return b.MySub +} |
