Documentation
¶
Overview ¶
Package tomlfilter provides TOML-based declarative filtering for command output. This enables users to define filters without writing Go code.
Index ¶
- func ReadFileLines(path string) ([]string, error)
- func ValidateFilter(name string, filter TomlFilter) error
- type FilterTest
- type MatchRule
- type Registry
- func (r *Registry) AllFilters() []*TomlFilter
- func (r *Registry) ApplyToCommand(command, input string) (string, bool)
- func (r *Registry) Count() int
- func (r *Registry) GetFilter(name string) *TomlFilter
- func (r *Registry) LoadFilters(directory string) error
- func (r *Registry) LoadFromEmbedded(content string) error
- func (r *Registry) MatchFilter(command string) *TomlFilter
- type ReplaceRule
- type TomlFilter
- type TomlFilterFile
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReadFileLines ¶
ReadFileLines reads a file and returns its lines.
func ValidateFilter ¶
func ValidateFilter(name string, filter TomlFilter) error
ValidateFilter validates a filter definition without adding it to the registry.
Types ¶
type FilterTest ¶
type FilterTest struct {
Name string `toml:"name"`
Input string `toml:"input"`
Expected string `toml:"expected"`
}
FilterTest represents an inline test case in a TOML filter.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry holds loaded TOML filters and provides matching functionality.
func (*Registry) AllFilters ¶
func (r *Registry) AllFilters() []*TomlFilter
AllFilters returns all loaded filters.
func (*Registry) ApplyToCommand ¶
ApplyToCommand finds a matching filter and applies it to the input. Returns the filtered output and true if a filter was applied, or the original input and false if no filter matched.
func (*Registry) GetFilter ¶
func (r *Registry) GetFilter(name string) *TomlFilter
GetFilter returns a filter by name, or nil if not found.
func (*Registry) LoadFilters ¶
LoadFilters loads all TOML filter files from the given directory.
func (*Registry) LoadFromEmbedded ¶
LoadFromEmbedded loads filters from embedded TOML content (for built-in filters).
func (*Registry) MatchFilter ¶
func (r *Registry) MatchFilter(command string) *TomlFilter
MatchFilter finds a filter that matches the given command. Returns nil if no filter matches.
type ReplaceRule ¶
ReplaceRule defines a regex substitution rule.
type TomlFilter ¶
type TomlFilter struct {
// Name is the filter identifier (from TOML table name)
Name string `toml:"-"`
// Description is a human-readable description of the filter
Description string `toml:"description"`
// MatchCommand is a regex pattern to match against the full command string
MatchCommand string `toml:"match_command"`
// StripANSI removes ANSI escape codes before processing
StripANSI bool `toml:"strip_ansi"`
// StripLinesMatching drops lines matching any of these regex patterns
StripLinesMatching []string `toml:"strip_lines_matching"`
// KeepLinesMatching keeps only lines matching at least one of these regex patterns
KeepLinesMatching []string `toml:"keep_lines_matching"`
// Replace applies regex substitutions
Replace []ReplaceRule `toml:"replace"`
// MatchOutput applies short-circuit rules based on output content
MatchOutput []MatchRule `toml:"match_output"`
// TruncateLinesAt truncates lines longer than N characters
TruncateLinesAt int `toml:"truncate_lines_at"`
// MaxLines keeps only the first N lines after filtering
MaxLines int `toml:"max_lines"`
// TailLines keeps only the last N lines (applied after other filters)
TailLines int `toml:"tail_lines"`
// OnEmpty is the fallback message when filtered output is empty
OnEmpty string `toml:"on_empty"`
// contains filtered or unexported fields
}
TomlFilter represents a single filter definition from a TOML file.
func (*TomlFilter) Apply ¶
func (f *TomlFilter) Apply(input string) string
Apply applies the filter to the input and returns the filtered output.
func (*TomlFilter) Matches ¶
func (f *TomlFilter) Matches(command string) bool
Matches checks if this filter should be applied to the given command.
type TomlFilterFile ¶
type TomlFilterFile struct {
Filters map[string]TomlFilter `toml:"filters"`
Tests map[string][]FilterTest `toml:"tests"`
}
TomlFilterFile represents the structure of a TOML filter file.