Documentation
¶
Overview ¶
Package yamlstore contains an implementation of config.Store that uses YAML files for persistence.
Index ¶
- Constants
- func ConfigDir(osArgs []string) (cfgDir string, origin config.Origin, err error)
- func Load(ctx context.Context, osArgs []string, optsReg *options.Registry, ...) (*config.Config, config.Store, error)
- func LoadVersionFromFile(path string) (string, error)
- type Store
- type UpgradeFunc
- type UpgradeRegistry
Constants ¶
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
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 ¶
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
Exists returns true if the backing file can be accessed, false if it doesn't exist or on any error.
type UpgradeFunc ¶
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.