mirror of
https://github.com/bitmagnet-io/bitmagnet.git
synced 2026-07-29 23:43:43 -04:00
94 lines
1.9 KiB
Go
94 lines
1.9 KiB
Go
package classifier
|
|
|
|
type Source struct {
|
|
Schema string `json:"$schema,omitempty" yaml:"$schema,omitempty"`
|
|
Workflows workflowSources `json:"workflows"`
|
|
FlagDefinitions flagDefinitions `json:"flag_definitions"`
|
|
Flags Flags `json:"flags"`
|
|
Keywords keywordGroups `json:"keywords"`
|
|
Extensions extensionGroups `json:"extensions"`
|
|
}
|
|
|
|
func (s Source) merge(other Source) (Source, error) {
|
|
flagDefs, err := s.FlagDefinitions.merge(other.FlagDefinitions)
|
|
if err != nil {
|
|
return Source{}, err
|
|
}
|
|
|
|
return Source{
|
|
FlagDefinitions: flagDefs,
|
|
Flags: s.Flags.merge(other.Flags),
|
|
Keywords: s.Keywords.merge(other.Keywords),
|
|
Extensions: s.Extensions.merge(other.Extensions),
|
|
Workflows: s.Workflows.merge(other.Workflows),
|
|
}, nil
|
|
}
|
|
|
|
func (s Source) workflowNames() map[Workflow]struct{} {
|
|
result := make(map[Workflow]struct{})
|
|
for k := range s.Workflows {
|
|
result[k] = struct{}{}
|
|
}
|
|
|
|
return result
|
|
}
|
|
|
|
type keywordGroups map[string][]string
|
|
|
|
func (g keywordGroups) merge(other keywordGroups) keywordGroups {
|
|
result := make(keywordGroups)
|
|
|
|
for k, v := range g {
|
|
if _, ok := other[k]; ok {
|
|
result[k] = append(v, other[k]...)
|
|
} else {
|
|
result[k] = v
|
|
}
|
|
}
|
|
|
|
for k, v := range other {
|
|
if _, ok := result[k]; !ok {
|
|
result[k] = v
|
|
}
|
|
}
|
|
|
|
return result
|
|
}
|
|
|
|
type extensionGroups map[string][]string
|
|
|
|
func (g extensionGroups) merge(other extensionGroups) extensionGroups {
|
|
result := make(extensionGroups)
|
|
|
|
for k, v := range g {
|
|
if _, ok := other[k]; ok {
|
|
result[k] = append(v, other[k]...)
|
|
} else {
|
|
result[k] = v
|
|
}
|
|
}
|
|
|
|
for k, v := range other {
|
|
if _, ok := result[k]; !ok {
|
|
result[k] = v
|
|
}
|
|
}
|
|
|
|
return result
|
|
}
|
|
|
|
type workflowSources map[Workflow]any
|
|
|
|
func (s workflowSources) merge(other workflowSources) workflowSources {
|
|
result := make(workflowSources)
|
|
for k, v := range s {
|
|
result[k] = v
|
|
}
|
|
|
|
for k, v := range other {
|
|
result[k] = v
|
|
}
|
|
|
|
return result
|
|
}
|