Documentation
¶
Index ¶
- Constants
- Variables
- func DetectFormatFromFilename(filename string) string
- func HasDifferences(results []*DiffResult) bool
- type ArrayDiffStrategy
- type Command
- type Controller
- type DataType
- type DiffEngine
- type DiffMeta
- type DiffOptions
- type DiffResult
- type DiffStatus
- type Formatter
- type JSONParser
- type JSONPatchFormatter
- type Location
- type Metadata
- type Parser
- type StringStyle
- type StructuredData
- type UnifiedFormatter
- type YAMLParser
Constants ¶
const ( FormatJSON = "json" FormatYAML = "yaml" FormatTOML = "toml" )
Format constants.
Variables ¶
var ( ErrInvalidArgs = errors.New("expected 2 files") ErrIncompatibleOptions = errors.New("--show-all and -C options are incompatible: context lines are only meaningful when showing only differences") )
var (
ErrUnsupportedFormat = errors.New("unsupported format")
)
Errors.
Functions ¶
func DetectFormatFromFilename ¶
DetectFormatFromFilename detects the format from filename extension.
func HasDifferences ¶
func HasDifferences(results []*DiffResult) bool
HasDifferences checks if there are any differences in the results.
Types ¶
type ArrayDiffStrategy ¶
type ArrayDiffStrategy int
ArrayDiffStrategy defines how to compare arrays.
const ( ArrayStrategyIndex ArrayDiffStrategy = iota // Compare by index ArrayStrategyValue // Find best matching )
type Command ¶
type Command struct {
// Flags
ShowAll bool
IgnoreZeroValues bool
IgnoreEmpty bool
IgnoreKeyCase bool
IgnoreValueCase bool
ArrayStrategy string
OutputFormat string
Format1 string
Format2 string
Verbose bool
Help bool
ContextLines int
// Arguments
File1 string
File2 string
// contains filtered or unexported fields
}
Command represents the CLI command configuration.
func NewCommand ¶
func NewCommand(name string, errorHandling flag.ErrorHandling) *Command
NewCommand creates a new Command instance.
func (*Command) GetDiffOptions ¶
func (c *Command) GetDiffOptions() DiffOptions
GetDiffOptions returns DiffOptions based on command flags.
func (*Command) GetFormat1 ¶
GetFormat1 returns the format for file1, auto-detecting if necessary.
func (*Command) GetFormat2 ¶
GetFormat2 returns the format for file2, auto-detecting if necessary.
func (*Command) GetFormatter ¶
GetFormatter returns the appropriate formatter based on command flags.
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
Controller handles the core diff logic.
func NewController ¶
func NewController(reader1, reader2 io.Reader, format1, format2 string, diffOpts DiffOptions, formatter Formatter, writer io.Writer) *Controller
NewController creates a new Controller.
func (*Controller) Run ¶
func (c *Controller) Run() (bool, error)
Run executes the diff process and returns whether differences were found.
type DiffEngine ¶
type DiffEngine struct {
// contains filtered or unexported fields
}
DiffEngine computes differences between structures.
func NewDiffEngine ¶
func NewDiffEngine(options DiffOptions) *DiffEngine
NewDiffEngine creates a new diff engine.
func (*DiffEngine) Compare ¶
func (e *DiffEngine) Compare(a, b *StructuredData) *DiffResult
Compare compares two structured data.
type DiffOptions ¶
type DiffOptions struct {
IgnoreEmptyFields bool
IgnoreZeroValues bool
IgnoreKeyCase bool
IgnoreValueCase bool
ArrayDiffStrategy ArrayDiffStrategy
}
DiffOptions contains options for diff computation.
type DiffResult ¶
type DiffResult struct {
Status DiffStatus
Path []string // Path to this element
From *StructuredData
To *StructuredData
Children []*DiffResult // For nested structures
Meta *DiffMeta
}
DiffResult represents the result of comparing two structures.
func Compare ¶
func Compare(docsA, docsB []*StructuredData, options DiffOptions) []*DiffResult
Compare compares multiple documents and finds optimal pairings.
type DiffStatus ¶
type DiffStatus int
DiffStatus represents the status of a diff.
const ( StatusSame DiffStatus = iota StatusModified StatusAdded StatusDeleted )
type Formatter ¶
type Formatter interface {
Format(w io.Writer, results []*DiffResult) error
}
Formatter interface for different output formats.
type JSONParser ¶
type JSONParser struct{}
JSONParser implements Parser for JSON.
func (*JSONParser) Format ¶
func (p *JSONParser) Format() string
func (*JSONParser) Parse ¶
func (p *JSONParser) Parse(reader io.Reader) ([]*StructuredData, error)
type JSONPatchFormatter ¶
type JSONPatchFormatter struct{}
JSONPatchFormatter implements RFC 6902 JSON Patch format.
func (*JSONPatchFormatter) Format ¶
func (f *JSONPatchFormatter) Format(w io.Writer, results []*DiffResult) error
Format formats diff results as JSON Patch.
type Metadata ¶
type Metadata struct {
Format string // "json", "yaml", "toml"
Location *Location // Position in source file
Comments []string // Comments (YAML/TOML)
StringStyle StringStyle // Style of string representation (for YAML)
}
Metadata contains format-specific information.
type Parser ¶
type Parser interface {
Parse(reader io.Reader) ([]*StructuredData, error)
Format() string
}
Parser interface for different formats.
type StringStyle ¶
type StringStyle int
StringStyle represents YAML string representation style.
const ( StringStyleUnknown StringStyle = iota StringStyleQuoted // "string" or 'string' StringStyleLiteral // | StringStyleFolded // > StringStylePlain // no quotes )
type StructuredData ¶
type StructuredData struct {
Type DataType
Value any // Actual value for primitives
Children map[string]*StructuredData // For objects
Elements []*StructuredData // For arrays
Meta *Metadata // Format-specific metadata
}
StructuredData represents format-agnostic structured data.
func ParseWithFormat ¶
func ParseWithFormat(reader io.Reader, format string) ([]*StructuredData, error)
ParseWithFormat parses content from reader with specified format.
type UnifiedFormatter ¶
UnifiedFormatter implements unified diff format.
func (*UnifiedFormatter) Format ¶
func (f *UnifiedFormatter) Format(w io.Writer, results []*DiffResult) error
Format formats diff results.
type YAMLParser ¶
type YAMLParser struct{}
YAMLParser implements Parser for YAML.
func (*YAMLParser) Format ¶
func (p *YAMLParser) Format() string
func (*YAMLParser) Parse ¶
func (p *YAMLParser) Parse(reader io.Reader) ([]*StructuredData, error)