filter

package
v0.10.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 8, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package filter provides filtering functionality for modules based on glob patterns and segment values. The public API surface is intentionally tiny:

  • Options describes which filters to apply
  • Apply runs the filters against a module slice
  • Flags collects filter values from CLI flags
  • ParseSegmentFilters parses --filter key=value strings

Concrete filter types (glob, segment, composite) are package-internal.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(modules []*discovery.Module, opts Options) ([]*discovery.Module, error)

Apply applies all configured filters to modules. Returns the input slice unchanged when no filter criteria are set.

func ParseSegmentFilters

func ParseSegmentFilters(args []string) map[string][]string

ParseSegmentFilters parses "key=value" strings into a segment filter map.

Types

type Flags added in v0.7.3

type Flags struct {
	Excludes    []string
	Includes    []string
	SegmentArgs []string
}

Flags holds parsed filter values from CLI flags. Source-agnostic — works with any CLI framework (cobra, etc.). Both core commands and feature extensions use this to collect filter inputs.

func (*Flags) Merge added in v0.7.3

func (f *Flags) Merge(cfgExcludes, cfgIncludes []string) Options

Merge combines config defaults with flag overrides into filter Options.

type Matcher added in v0.10.0

type Matcher struct {
	// contains filtered or unexported fields
}

Matcher is a validated filter predicate. Build one with Options.Compile() to amortize filter construction across many module checks — callers that invoke Apply on slice-of-1 inside a loop can hoist Compile() out and reuse the Matcher in the inner loop.

func (Matcher) Empty added in v0.10.0

func (m Matcher) Empty() bool

Empty reports whether the matcher has no active filters; callers can short-circuit and accept every module.

func (Matcher) Matches added in v0.10.0

func (m Matcher) Matches(module *discovery.Module) bool

Matches reports whether a module passes all configured filters.

type Options

type Options struct {
	Excludes []string            // glob patterns to exclude
	Includes []string            // glob patterns to include (empty = all)
	Segments map[string][]string // segment name → allowed values (e.g. "service" → ["platform"])
}

Options contains all filter parameters.

func (Options) Compile added in v0.10.0

func (o Options) Compile() (Matcher, error)

Compile builds a reusable Matcher from Options. Equivalent to extracting the internal filter list once instead of rebuilding it per Apply call.

func (Options) Validate added in v0.10.3

func (o Options) Validate() error

Validate checks filter options before they are compiled.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL