toml

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const SchemaVersion = 1

SchemaVersion is the expected TOML filter schema version

Variables

This section is empty.

Functions

func ApplyTOMLFilter

func ApplyTOMLFilter(input string, config *TOMLFilterRule) (string, int)

ApplyTOMLFilter is a convenience function to apply a TOML filter config

func FormatSafetyReport

func FormatSafetyReport(check SafetyCheck) string

FormatSafetyReport formats a safety check result as a human-readable string

func IsPrintableASCII

func IsPrintableASCII(s string) bool

IsPrintableASCII checks if a string contains only printable ASCII characters

func MatchAndFilter

func MatchAndFilter(command string, output string, registry *FilterRegistry) (string, int, bool)

MatchAndFilter finds a matching filter and applies it

func ValidateFilterConfig

func ValidateFilterConfig(content string) []error

ValidateFilterConfig validates TOML filter configuration syntax

Types

type FilterConflict added in v0.28.0

type FilterConflict struct {
	Filter1  string
	Filter2  string
	Pattern1 string
	Pattern2 string
	Type     string // "shadow", "duplicate", "overlap"
}

FilterConflict represents a potential filter conflict

type FilterRegistry

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

FilterRegistry holds all loaded TOML filters

func NewFilterRegistry

func NewFilterRegistry() *FilterRegistry

NewFilterRegistry creates a new filter registry

func (*FilterRegistry) Count

func (r *FilterRegistry) Count() int

Count returns the number of loaded filters

func (*FilterRegistry) DetectConflicts added in v0.28.0

func (r *FilterRegistry) DetectConflicts() []FilterConflict

DetectConflicts analyzes all loaded filters and reports potential conflicts

func (*FilterRegistry) FindMatchingFilter

func (r *FilterRegistry) FindMatchingFilter(command string) (string, string, *TOMLFilterRule)

FindMatchingFilter finds a filter that matches the given command

func (*FilterRegistry) LoadFile

func (r *FilterRegistry) LoadFile(path string) error

LoadFile loads a single TOML filter file

type FilterTest added in v0.28.0

type FilterTest struct {
	Name     string `toml:"name"`
	Input    string `toml:"input"`
	Expected string `toml:"expected"`
	Command  string `toml:"command,omitempty"` // Optional command to match
}

FilterTest represents an inline test case for a filter

type FilterTestSuite

type FilterTestSuite struct {
	Tests map[string][]TOMLFilterTest // map[filterName][]tests
}

FilterTestSuite represents a collection of tests for filters

func NewFilterTestSuite

func NewFilterTestSuite() *FilterTestSuite

NewFilterTestSuite creates a new filter test suite

func ParseTests

func ParseTests(raw map[string]any) (*FilterTestSuite, error)

ParseTests extracts test cases from TOML raw content

func (*FilterTestSuite) AddTest

func (ts *FilterTestSuite) AddTest(filterName string, test TOMLFilterTest)

AddTest adds a test to the suite

func (*FilterTestSuite) GetTests

func (ts *FilterTestSuite) GetTests(filterName string) []TOMLFilterTest

GetTests returns all tests for a specific filter

func (*FilterTestSuite) RunAllTests

func (ts *FilterTestSuite) RunAllTests(filterFuncs map[string]func(string) string) []TestResult

RunAllTests executes all tests in the suite

func (*FilterTestSuite) RunTest

func (ts *FilterTestSuite) RunTest(filterName string, test TOMLFilterTest, filterFunc func(string) string) TestResult

RunTest executes a single test

func (*FilterTestSuite) TotalTests

func (ts *FilterTestSuite) TotalTests() int

TotalTests returns the total number of tests

type Loader

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

Loader handles loading TOML filters from multiple sources

var GlobalFilterLoader *Loader

GlobalFilterLoader is the default loader instance

func GetLoader

func GetLoader() *Loader

GetLoader returns the global filter loader (singleton)

func NewLoader

func NewLoader(configDir string) *Loader

NewLoader creates a new filter loader

func (*Loader) IsTrusted

func (l *Loader) IsTrusted(projectPath string) bool

IsTrusted checks if a project directory is trusted

func (*Loader) ListTrusted

func (l *Loader) ListTrusted() []string

ListTrusted returns all trusted project paths

func (*Loader) LoadAll

func (l *Loader) LoadAll(projectDir string) (*FilterRegistry, error)

LoadAll loads filters from all sources with priority order: 1. Project-local: .tokman/filters.toml (requires trust) 2. User-global: ~/.config/tokman/filters.toml 3. Built-in: embedded filters

func (*Loader) LoadTrusted

func (l *Loader) LoadTrusted() error

LoadTrusted loads the trusted projects file

func (*Loader) TrustProject

func (l *Loader) TrustProject(projectPath string) error

TrustProject marks a project directory as trusted for filter loading

func (*Loader) UntrustProject

func (l *Loader) UntrustProject(projectPath string) error

UntrustProject removes a project from the trusted list

type LoaderConfig

type LoaderConfig struct {
	ConfigDir  string // Base config directory (default: ~/.config/tokman)
	DataDir    string // Base data directory (default: ~/.local/share/tokman)
	ProjectDir string // Current project directory
}

LoaderConfig configures the filter loader

type MatchOutputRule

type MatchOutputRule struct {
	Pattern  string `toml:"pattern"`
	Message  string `toml:"message"`
	Priority int    `toml:"priority"`
	Unless   string `toml:"unless"` // Optional: if this pattern also matches, skip the rule
}

MatchOutputRule defines a short-circuit match rule If pattern matches, returns message immediately (short-circuit). If unless is set and also matches, the rule is skipped (prevents swallowing errors).

type Parser

type Parser struct{}

Parser handles parsing TOML filter files

func NewParser

func NewParser() *Parser

NewParser creates a new TOML filter parser

func (*Parser) ParseContent

func (p *Parser) ParseContent(content []byte, source string) (*TOMLFilter, error)

ParseContent parses TOML filter content

func (*Parser) ParseFile

func (p *Parser) ParseFile(path string) (*TOMLFilter, error)

ParseFile parses a single TOML filter file

type ReplaceRule

type ReplaceRule struct {
	Pattern     string `toml:"pattern"`
	Replacement string `toml:"replacement"`
}

ReplaceRule defines a regex replacement rule

type SafetyCheck

type SafetyCheck struct {
	Passed bool
	Issues []SafetyIssue
}

SafetyCheck represents the result of a safety validation

func CheckFilterSafety

func CheckFilterSafety(content string) SafetyCheck

CheckFilterSafety performs safety checks on TOML filter content

type SafetyIssue

type SafetyIssue struct {
	Severity string
	Message  string
	Line     int
}

SafetyIssue represents a single safety issue found

type TOMLFilter

type TOMLFilter struct {
	SchemaVersion int                       `toml:"schema_version"`
	Filters       map[string]TOMLFilterRule `toml:"-"`
	RawContent    map[string]any            `toml:"-"`
}

TOMLFilter represents a parsed TOML filter file

func (*TOMLFilter) MatchesCommand

func (f *TOMLFilter) MatchesCommand(command string) (string, *TOMLFilterRule, error)

MatchesCommand checks if any filter matches the given command

func (*TOMLFilter) RunTests added in v0.28.0

func (f *TOMLFilter) RunTests() ([]TestResult, error)

RunTests executes all inline tests for this filter and returns results

func (*TOMLFilter) Validate

func (f *TOMLFilter) Validate() error

Validate validates the filter configuration

type TOMLFilterEngine

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

TOMLFilterEngine applies TOML-defined filter rules to output

func NewTOMLFilterEngine

func NewTOMLFilterEngine(config *TOMLFilterRule) *TOMLFilterEngine

NewTOMLFilterEngine creates a new filter engine from a TOML config

func (*TOMLFilterEngine) Apply

func (e *TOMLFilterEngine) Apply(input string, mode filter.Mode) (string, int)

Apply applies the filter rules to the input

type TOMLFilterRule

type TOMLFilterRule struct {
	MatchCommand       string            `toml:"match_command"`
	StripANSI          bool              `toml:"strip_ansi"`
	Replace            []ReplaceRule     `toml:"replace"`
	MatchOutput        []MatchOutputRule `toml:"match_output"`
	StripLinesMatching []string          `toml:"strip_lines_matching"`
	KeepLinesMatching  []string          `toml:"keep_lines_matching"`
	TruncateLinesAt    int               `toml:"truncate_lines_at"`
	Head               int               `toml:"head"`
	Tail               int               `toml:"tail"`
	MaxLines           int               `toml:"max_lines"`
	OnEmpty            string            `toml:"on_empty"`
	CaptureStderr      bool              `toml:"capture_stderr"` // Capture stderr output for filtering
	Tests              []FilterTest      `toml:"tests"`          // Inline test definitions
}

TOMLFilterRule represents a single TOML filter rule configuration

type TOMLFilterTest

type TOMLFilterTest struct {
	Name     string `toml:"name"`
	Input    string `toml:"input"`
	Expected string `toml:"expected"`
	Skip     bool   `toml:"skip"`
	Reason   string `toml:"reason"`
}

TOMLFilterTest represents an inline test case for a filter

type TOMLFilterWrapper

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

TOMLFilterWrapper implements the filter.Filter interface for TOML filters

func NewTOMLFilterWrapper

func NewTOMLFilterWrapper(name string, config *TOMLFilterRule) *TOMLFilterWrapper

NewTOMLFilterWrapper creates a filter.Filter wrapper for a TOML filter

func (*TOMLFilterWrapper) Apply

func (f *TOMLFilterWrapper) Apply(input string, mode filter.Mode) (string, int)

Apply implements the filter.Filter interface

func (*TOMLFilterWrapper) Name

func (f *TOMLFilterWrapper) Name() string

Name returns the filter name

type TestResult

type TestResult struct {
	FilterName string
	TestName   string
	Passed     bool
	Expected   string
	Got        string
	Error      error
	Skipped    bool
	Reason     string
}

TestResult represents the result of running a single test

type TestSummary

type TestSummary struct {
	Total   int
	Passed  int
	Failed  int
	Skipped int
	Results []TestResult
}

Summary returns a summary of test results

func Summarize

func Summarize(results []TestResult) TestSummary

Summarize creates a summary from test results

func (TestSummary) FormatSummary

func (s TestSummary) FormatSummary() string

FormatSummary formats a test summary for display

Jump to

Keyboard shortcuts

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