diff --git a/internal/config/autoconfig/autoconfig.go b/internal/config/autoconfig/autoconfig.go index a3697355..7007bab6 100644 --- a/internal/config/autoconfig/autoconfig.go +++ b/internal/config/autoconfig/autoconfig.go @@ -171,7 +171,6 @@ func getProjectFilters(c *config.Config) ([]project.Filter, error) { filters = append(filters, project.Filter(func(t project.Task) (bool, error) { env := config.FilterBlockEnv{ Background: t.CodeBlock.Background(), - Tags: t.CodeBlock.Tags(), // TODO(adamb): implement this in the code block. // CloseTerminalOnSuccess: t.CodeBlock.CloseTerminalOnSuccess(), Cwd: t.CodeBlock.Cwd(), @@ -181,6 +180,7 @@ func getProjectFilters(c *config.Config) ([]project.Filter, error) { Language: t.CodeBlock.Language(), Name: t.CodeBlock.Name(), PromptEnv: t.CodeBlock.PromptEnv(), + Tags: t.CodeBlock.Tags(), } return filter.Evaluate(env) })) diff --git a/internal/config/config_filter.go b/internal/config/config_filter.go index bb5c0df0..22d9107c 100644 --- a/internal/config/config_filter.go +++ b/internal/config/config_filter.go @@ -34,7 +34,6 @@ type FilterDocumentEnv struct { // Without it, all variables start with capitalized letters. type FilterBlockEnv struct { Background bool `expr:"background"` - Tags []string `expr:"tags"` CloseTerminalOnSuccess bool `expr:"close_terminal_on_success"` Cwd string `expr:"cwd"` ExcludeFromRunAll bool `expr:"exclude_from_run_all"` @@ -43,6 +42,7 @@ type FilterBlockEnv struct { Language string `expr:"language"` Name string `expr:"name"` PromptEnv bool `expr:"prompt_env"` + Tags []string `expr:"tags"` } type filterDocumentWithExtraEnv struct { diff --git a/pkg/api/proto/runme/parser/v1/parser.proto b/pkg/api/proto/runme/parser/v1/parser.proto index 5dd863ef..6f5627d2 100644 --- a/pkg/api/proto/runme/parser/v1/parser.proto +++ b/pkg/api/proto/runme/parser/v1/parser.proto @@ -93,6 +93,7 @@ message Frontmatter { string cwd = 2; bool skip_prompts = 3; FrontmatterRunme runme = 4; + // Deprecated category in favor of Tag string category = 5; string terminal_rows = 6; string tag = 7; diff --git a/pkg/document/block.go b/pkg/document/block.go index 535a87ac..cde68a7b 100644 --- a/pkg/document/block.go +++ b/pkg/document/block.go @@ -103,15 +103,19 @@ func (b *CodeBlock) Background() bool { } func (b *CodeBlock) Tags() []string { - tag, ok := b.Attributes()["category"] - if !ok { - tag, ok = b.Attributes()["tag"] + var superset []string + + categories, ok := b.Attributes()["category"] + if ok { + superset = append(superset, strings.Split(categories, ",")...) } - if !ok { - return nil + tags, ok := b.Attributes()["tags"] + if ok { + superset = append(superset, strings.Split(tags, ",")...) } - return strings.Split(tag, ",") + + return superset } func (b *CodeBlock) Clone() *CodeBlock { diff --git a/pkg/document/block_test.go b/pkg/document/block_test.go index 8ffb27f9..cdd84d4c 100644 --- a/pkg/document/block_test.go +++ b/pkg/document/block_test.go @@ -33,3 +33,15 @@ func TestBlock_Clone(t *testing.T) { block.value[0] = 'a' assert.NotEqual(t, block.value[0], clone.value[0]) } + +func TestBlock_Tags(t *testing.T) { + t.Run("Superset including legacy categories", func(t *testing.T) { + block := &CodeBlock{ + attributes: map[string]string{ + "category": "cat1,cat2", + "tags": "tag1,tag2", + }, + } + assert.Equal(t, []string{"cat1", "cat2", "tag1", "tag2"}, block.Tags()) + }) +} diff --git a/pkg/document/frontmatter.go b/pkg/document/frontmatter.go index 44074839..bbd7cfc8 100644 --- a/pkg/document/frontmatter.go +++ b/pkg/document/frontmatter.go @@ -54,13 +54,14 @@ func (m *RunmeMetadata) IsEmpty() bool { } type Frontmatter struct { - Runme *RunmeMetadata `yaml:"runme,omitempty"` - Shell string `yaml:"shell"` - Cwd string `yaml:"cwd"` - Category string `yaml:"category"` - Tag string `yaml:"tag"` - TerminalRows string `yaml:"terminalRows"` - SkipPrompts bool `yaml:"skipPrompts,omitempty"` + Runme *RunmeMetadata `yaml:"runme,omitempty"` + Shell string `yaml:"shell"` + Cwd string `yaml:"cwd"` + // Deprecated Category in favor of Tag + Category string `yaml:"category"` + Tag string `yaml:"tag"` + TerminalRows string `yaml:"terminalRows"` + SkipPrompts bool `yaml:"skipPrompts,omitempty"` format string raw string // using string to be able to compare using ==