update

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: BSD-3-Clause Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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) UpdateJSONValue added in v0.2.2

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

UpdateJSONValue does a targeted value replacement in a JSON file, preserving key order and formatting. It edits only the scalar at the given path in the raw bytes, leaving the rest of the document byte-for-byte intact — unlike a parse-then-marshal round-trip, which loses key order (Go marshals maps with keys sorted alphabetically). The path uses gjson/sjson dot syntax, e.g. "version" or "packages.dependencies.foo".

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