yamlstore

package
v0.48.3 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package yamlstore contains an implementation of config.Store that uses YAML files for persistence.

Index

Constants

View Source
const MinConfigVersion = "v0.0.0-dev"

MinConfigVersion is the minimum semver value of Config.Version. This is basically how far back in time the config upgrade process can support. If the config dates from prior to this (unlikely), then the user needs to start with a new config.

Variables

This section is empty.

Functions

func ConfigDir added in v0.48.0

func ConfigDir(osArgs []string) (cfgDir string, origin config.Origin, err error)

ConfigDir returns the config dir, and the origin of the config dir.

func Load

func Load(ctx context.Context, osArgs []string, optsReg *options.Registry,
	upgrades UpgradeRegistry,
) (*config.Config, config.Store, error)

Load loads sq config from the default location (~/.config/sq/sq.yml) or the location specified in envars or flags.

func LoadVersionFromFile

func LoadVersionFromFile(path string) (string, error)

LoadVersionFromFile loads the version from the config file. If the field is not present, minConfigVersion (and no error) is returned.

Types

type Store

type Store struct {
	// If HookLoad is non-nil, it is invoked by Load
	// on Path's bytes before the YAML is unmarshalled.
	// This allows expansion of variables etc.
	HookLoad func(data []byte) ([]byte, error)

	// UpgradeRegistry holds upgrade funcs for upgrading the config file.
	UpgradeRegistry UpgradeRegistry

	// OptionsRegistry holds options.
	OptionsRegistry *options.Registry
	// Path is the location of the config file
	Path string

	// PathOrigin is one of "flag", "env", or "default".
	PathOrigin config.Origin

	// ExtPaths holds locations of potential ext config, both dirs and files (with suffix ".sq.yml")
	ExtPaths []string
}

Store provides persistence of config via YAML file. It implements config.Store.

func (*Store) Exists added in v0.47.2

func (fs *Store) Exists() bool

Exists returns true if the backing file can be accessed, false if it doesn't exist or on any error.

func (*Store) Load

func (fs *Store) Load(ctx context.Context) (*config.Config, error)

Load reads config from disk. It implements Store.

func (*Store) Location

func (fs *Store) Location() string

Location implements Store. It returns the location of the config dir.

func (*Store) Lockfile added in v0.47.0

func (fs *Store) Lockfile() (lockfile.Lockfile, error)

Lockfile implements Store.Lockfile.

func (*Store) Save

func (fs *Store) Save(ctx context.Context, cfg *config.Config) error

Save writes config to disk. It implements Store.

func (*Store) String

func (fs *Store) String() string

String returns a log/debug-friendly representation.

type UpgradeFunc

type UpgradeFunc func(ctx context.Context, before []byte) (after []byte, err error)

UpgradeFunc performs a (single) upgrade of the config file. Typically a func will read the config data from disk, perform some transformation on it, and write it back out to disk. Note that the func should not bind the config file YAML to the Config object, as they may differ significantly. Instead, the func should bind the YAML to a map, and manipulate that map directly.

type UpgradeRegistry

type UpgradeRegistry map[string]UpgradeFunc

UpgradeRegistry is a map of config_version to upgrade funcs.

Directories

Path Synopsis
upgrades
v0.34.0
Package v0_34_0 upgrades YAML config to v0.34.0.
Package v0_34_0 upgrades YAML config to v0.34.0.

Jump to

Keyboard shortcuts

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