Documentation
¶
Overview ¶
Package parser provides a unified interface for reading version information from various file formats including JSON, YAML, TOML, raw text, and regex patterns. It is used by both the dependency-check plugin and the discovery service.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FieldForFormat ¶
FieldForFormat returns the typical field path for common file types.
Types ¶
type FileConfig ¶
type FileConfig struct {
// Path is the file path (absolute or relative).
Path string
// Format specifies the file format.
Format Format
// Field is the dot-notation path to the version field (for JSON/YAML/TOML).
// Example: "version", "package.version", "tool.poetry.version"
Field string
// Pattern is the regex pattern for regex format.
// Must contain a capturing group for the version.
Pattern string
}
FileConfig describes how to read a version from a specific file.
type Format ¶
type Format string
Format represents the supported file formats for version parsing.
const ( // FormatJSON is for JSON files (package.json, etc.). FormatJSON Format = "json" // FormatYAML is for YAML files (Chart.yaml, etc.). FormatYAML Format = "yaml" // FormatTOML is for TOML files (Cargo.toml, pyproject.toml, etc.). FormatTOML Format = "toml" // FormatRaw is for plain text files where the entire content is the version. FormatRaw Format = "raw" // FormatRegex is for files requiring regex extraction. FormatRegex Format = "regex" )
func FormatForFile ¶
FormatForFile detects the format based on file extension or name.
func ParseFormat ¶
ParseFormat converts a string to a Format, returning FormatRaw as fallback.
type ReadWriter ¶
ReadWriter combines Reader and Writer functionality.
func NewReadWriter ¶
func NewReadWriter(fs core.FileSystem) *ReadWriter
NewReadWriter creates a new ReadWriter with the given filesystem.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader provides version reading capabilities for multiple file formats.
func NewReader ¶
func NewReader(fs core.FileSystem) *Reader
NewReader creates a new Reader with the given filesystem.
func (*Reader) ReadVersion ¶
ReadVersion is a convenience method that reads and returns just the version string.
type Result ¶
type Result struct {
// Version is the extracted version string.
Version string
// Path is the file path that was read.
Path string
// Format is the format that was used.
Format Format
// Field is the field path that was used (for structured formats).
Field string
}
Result represents the result of reading a version from a file.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer provides version writing capabilities for multiple file formats.
func NewWriter ¶
func NewWriter(fs core.FileSystem) *Writer
NewWriter creates a new Writer with the given filesystem.