diff options
| author | ewy <ewy0@protonmail.com> | 2026-06-01 18:47:44 +0200 |
|---|---|---|
| committer | ewy <ewy0@protonmail.com> | 2026-06-01 18:47:44 +0200 |
| commit | 46d032cd21b0e8e2c94a32333d3805ec76980cca (patch) | |
| tree | fbb8aed5c5a501aca1309f62a9d4440ca949ce4c /indexers | |
| parent | 7585a488b7b1e1812f7ebf50107139e2fd65f035 (diff) | |
add man(1) generation
Diffstat (limited to 'indexers')
| -rw-r--r-- | indexers/pikdex/index.go | 8 | ||||
| -rw-r--r-- | indexers/pikdex/meta.go | 43 | ||||
| -rw-r--r-- | indexers/pikdex/meta_test.go | 39 |
3 files changed, 76 insertions, 14 deletions
diff --git a/indexers/pikdex/index.go b/indexers/pikdex/index.go index 70cfabb..1a9b38a 100644 --- a/indexers/pikdex/index.go +++ b/indexers/pikdex/index.go @@ -43,9 +43,11 @@ type pikdex struct { } type SourceData struct { - Aliases []string - Icon string - Path string + Aliases []string + Icon string + Path string + Wants []string + Includes []string } func (u *pikdex) Index(absPath string, f fs.FS, runners []model.Runner) ([]model.Target, error) { diff --git a/indexers/pikdex/meta.go b/indexers/pikdex/meta.go index 750ce47..ef2c029 100644 --- a/indexers/pikdex/meta.go +++ b/indexers/pikdex/meta.go @@ -2,24 +2,28 @@ package pikdex import ( "github.com/charmbracelet/lipgloss" + "github.com/ewy1/pik/describe" "strings" ) type MetaSetter func(s *SourceData, content string) var MetaFiles = map[string]MetaSetter{ + ".wants": func(s *SourceData, content string) { + s.Wants = contentLines(content) + }, + ".includes": func(s *SourceData, content string) { + s.Includes = contentLines(content) + }, ".alias": func(s *SourceData, content string) { - split := strings.Split(content, "\n") - s.Aliases = make([]string, 0, len(split)) - for _, line := range split { - stripped := strip(line) - if stripped != "" { - s.Aliases = append(s.Aliases, stripped) - } - } + s.Aliases = contentLines(content) }, ".icon": func(s *SourceData, content string) { - icon := strip(content) + lines := contentLines(content) + if len(lines) == 0 { + return + } + icon := lines[0] desiredWidth := lipgloss.Width(icon) diff := desiredWidth - len([]rune(icon)) icon += strings.Repeat(" ", diff) @@ -27,6 +31,23 @@ var MetaFiles = map[string]MetaSetter{ }, } -func strip(input string) string { - return strings.TrimSpace(input) +func contentLines(input string) []string { + result := make([]string, 0, len(input)) +nextLine: + for _, l := range strings.Split(input, "\n") { + l = strings.TrimSpace(l) + + if l == "" { + continue nextLine + } + + for _, c := range describe.CommentPrefixes { + if strings.HasPrefix(l, c) { + continue nextLine + } + } + + result = append(result, l) + } + return result } diff --git a/indexers/pikdex/meta_test.go b/indexers/pikdex/meta_test.go new file mode 100644 index 0000000..e04815f --- /dev/null +++ b/indexers/pikdex/meta_test.go @@ -0,0 +1,39 @@ +//go:build test + +package pikdex + +import ( + "github.com/stretchr/testify/assert" + "testing" +) + +func TestContentLines(t *testing.T) { + in := `asdf +hjkl` + result := contentLines(in) + assert.Equal(t, "asdf", "hjkl", result) +} + +func TestContentLines_EmptyLine(t *testing.T) { + in := `asdf + +hjkl` + result := contentLines(in) + assert.Equal(t, "asdf", "hjkl", result) +} + +func TestContentLines_Empty(t *testing.T) { + in := `` + result := contentLines(in) + assert.Equal(t, nil, result) +} + +func TestContentLines_Comment(t *testing.T) { + in := ` +//aaa +asdf +# iuyyiuoui +hjkl` + result := contentLines(in) + assert.Equal(t, "asdf", "hjkl", result) +} |
