config

package
v0.47.1 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package config holds CLI configuration.

Index

Constants

View Source
const (
	// EnvarLogPath is the log file path.
	EnvarLogPath = "SQ_LOG_FILE"

	// EnvarLogLevel is the log level. It maps to a slog.Level.
	EnvarLogLevel = "SQ_LOG_LEVEL"

	// EnvarLogFormat is the log format. It maps to a slog.Level.
	EnvarLogFormat = "SQ_LOG_FORMAT"

	// EnvarLogEnabled turns logging on or off.
	EnvarLogEnabled = "SQ_LOG"

	// EnvarConfigDir is the legacy envar for config location.
	// Instead use EnvarConfig.
	EnvarConfigDir = "SQ_CONFIGDIR"

	// EnvarConfig is the envar for config location.
	EnvarConfig = "SQ_CONFIG"
)

Variables

View Source
var OptConfigLockTimeout = options.NewDuration(
	"config.lock.timeout",
	"",
	0,
	time.Second*5,
	"Wait timeout to acquire config lock",
	`Wait timeout to acquire the config lock (which prevents multiple sq instances
stepping on each other's config changes). During this period, retry will occur
if the lock is already held by another process. If zero, no retry occurs.`,
)

OptConfigLockTimeout is the time allowed to acquire the config lock.

Functions

func Valid added in v0.34.0

func Valid(cfg *Config) error

Valid returns an error if cfg is not valid.

Types

type Config

type Config struct {
	// Version is the config version. This will allow sq to
	// upgrade config files if needed. It must be a valid semver.
	Version string `yaml:"config.version" json:"config_version"`

	// Options contains default settings, such as output format.
	Options options.Options `yaml:"options" json:"options"`

	// Collection is the set of data sources.
	Collection *source.Collection `yaml:"collection" json:"collection"`

	// Ext holds sq config extensions, such as user driver config.
	Ext Ext `yaml:"-" json:"-"`
}

Config holds application config/session data.

func New

func New() *Config

New returns a config instance with default options set.

func (*Config) String

func (c *Config) String() string

String returns a log/debug-friendly representation.

type DiscardStore

type DiscardStore struct{}

DiscardStore implements Store but its Save method is no-op and Load always returns a new empty Config. Useful for testing.

func (DiscardStore) Load

Load returns a new empty Config.

func (DiscardStore) Location

func (DiscardStore) Location() string

Location returns /dev/null.

func (DiscardStore) Lockfile added in v0.47.0

func (DiscardStore) Lockfile() (lockfile.Lockfile, error)

Lockfile implements Store.Lockfile.

func (DiscardStore) Save

Save is no-op.

type Ext

type Ext struct {
	UserDrivers []*userdriver.DriverDef `yaml:"user_drivers" json:"user_drivers"`
}

Ext holds additional config (extensions) loaded from other config files, e.g. ~/.config/sq/ext/*.sq.yml.

type Store

type Store interface {
	// Save writes config to the store.
	Save(ctx context.Context, cfg *Config) error

	// Load reads config from the store.
	Load(ctx context.Context) (*Config, error)

	// Location returns the location of the store, typically
	// a file path.
	Location() string

	// Lockfile returns the lockfile used by the store, but does not acquire
	// the lock, which is the caller's responsibility. The lock should always
	// be acquired before mutating config. It is also the caller's responsibility
	// to release the acquired lock when done.
	Lockfile() (lockfile.Lockfile, error)
}

Store saves and loads config.

Directories

Path Synopsis
Package yamlstore contains an implementation of config.Store that uses YAML files for persistence.
Package yamlstore contains an implementation of config.Store that uses YAML files for persistence.
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