update

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2026 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrFileNotFound      = "file not found"
	ErrPathNotFound      = "path not found in file"
	ErrInvalidSelector   = "invalid selector syntax"
	ErrUnsupportedFormat = "unsupported file format"
	ErrFileParseFailed   = "failed to parse file"
	ErrFileWriteFailed   = "failed to write file"
	ErrTemplateRender    = "failed to render template"
)

Error messages

View Source
const (
	LogFileUpdated      = "file_updated"
	LogUpdateSkipped    = "update_skipped"
	LogUpdatesApplied   = "updates_applied"
	LogValidatingConfig = "validating_update_config"
)

Log messages for structured logging

View Source
const FilePermission os.FileMode = 0644

FilePermission is the default permission for written files

Variables

This section is empty.

Functions

This section is empty.

Types

type DaselFileParser

type DaselFileParser struct{}

DaselFileParser implements FileParser using dasel for path queries

func NewDaselFileParser

func NewDaselFileParser() *DaselFileParser

NewDaselFileParser creates a new DaselFileParser

func (*DaselFileParser) Put

func (p *DaselFileParser) Put(data *map[string]any, path string, value any) error

Put updates a value at the given path using dasel syntax

func (*DaselFileParser) Read

func (p *DaselFileParser) Read(path string) (any, Format, error)

Read reads and parses a structured file

func (*DaselFileParser) ReadWithFormat

func (p *DaselFileParser) ReadWithFormat(path string, explicitFormat string) (any, Format, error)

ReadWithFormat reads a file using an explicit format

func (*DaselFileParser) Select

func (p *DaselFileParser) Select(data any, path string) (any, error)

Select retrieves a value at the given path using dasel syntax

func (*DaselFileParser) UpdateTOMLValue

func (p *DaselFileParser) UpdateTOMLValue(filePath string, path string, newValue string) error

UpdateTOMLValue does a targeted value replacement in a TOML file, preserving comments, ordering, and formatting. Parses to find the old value at the path, then replaces it in the raw bytes.

func (*DaselFileParser) Write

func (p *DaselFileParser) Write(path string, data any, format Format) error

Write writes data back to file in the specified format

type FileParser

type FileParser interface {
	// Read reads and parses a structured file, returning the data and detected format
	Read(filepath string) (any, Format, error)
	// Write writes data back to file in the specified format
	Write(filepath string, data any, format Format) error
	// Select retrieves a value at the given path using dasel syntax
	Select(data any, path string) (any, error)
	// Put updates a value at the given path using dasel syntax
	Put(data *map[string]any, path string, value any) error
}

FileParser provides operations on structured files (JSON, YAML, TOML)

type FileUpdater

type FileUpdater interface {
	// UpdateFiles applies all configured updates using the given template data
	UpdateFiles(data emit.TemplateData) error
	// ValidateConfig checks all update configurations are valid
	ValidateConfig() error
	// GetFilesToCommit returns list of files that were modified
	GetFilesToCommit() []string
}

FileUpdater defines the interface for file update operations

type Format

type Format string

Format represents supported file formats

const (
	FormatJSON Format = "json"
	FormatYAML Format = "yaml"
	FormatTOML Format = "toml"
)

type Updater

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

Updater implements FileUpdater with actual file operations

func NewUpdater

func NewUpdater(configs []config.UpdateConfig, parser *DaselFileParser, logger *zap.Logger) *Updater

NewUpdater creates an Updater (IoC constructor accepting dependencies)

func NewUpdaterDefault

func NewUpdaterDefault(configs []config.UpdateConfig) (*Updater, error)

NewUpdaterDefault creates an Updater with default dependencies This is excluded from unit test coverage as it's tested via integration tests

func (*Updater) GetFilesToCommit

func (u *Updater) GetFilesToCommit() []string

GetFilesToCommit returns list of files that were modified

func (*Updater) UpdateFiles

func (u *Updater) UpdateFiles(data emit.TemplateData) error

UpdateFiles applies all configured updates using the given template data

func (*Updater) ValidateConfig

func (u *Updater) ValidateConfig() error

ValidateConfig checks all update configurations are valid

Jump to

Keyboard shortcuts

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