config

package
v0.23.1 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package config holds CLI configuration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Version is the config version. This will allow sq to
	// upgrade config files if needed.
	Version string `yaml:"version" json:"version"`

	// Defaults contains default settings, such as output format.
	Defaults Defaults `yaml:"defaults" json:"defaults"`

	// Sources is the set of data sources.
	Sources *source.Set `yaml:"sources" json:"sources"`

	// 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

type Defaults

type Defaults struct {
	// Format is the default output format: json, table, etc.
	Format Format `yaml:"output_format" json:"output_format"`

	// Header determines if a header should be printed (if relevant
	// for the output format).
	Header bool `yaml:"output_header" json:"output_header"`

	// PingTimeout is the allowed time for a ping.
	PingTimeout time.Duration `yaml:"ping_timeout" json:"ping_timeout"`

	// ShellCompletionTimeout is the time allowed for the shell
	// completion callback to execute.
	ShellCompletionTimeout time.Duration `yaml:"shell_completion_timeout" json:"shell_completion_timeout"`
}

Defaults contains default config values.

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

func (DiscardStore) Load() (*Config, error)

Load returns a new empty Config.

func (DiscardStore) Location

func (DiscardStore) Location() string

Location returns /dev/null.

func (DiscardStore) Save

func (DiscardStore) Save(*Config) error

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 Format

type Format string

Format is a sq output format such as json or xml.

const (
	FormatJSON     Format = "json"
	FormatJSONL    Format = "jsonl"
	FormatJSONA    Format = "jsona"
	FormatTable    Format = "table"
	FormatRaw      Format = "raw"
	FormatHTML     Format = "html"
	FormatMarkdown Format = "markdown"
	FormatXLSX     Format = "xlsx"
	FormatXML      Format = "xml"
	FormatCSV      Format = "csv"
	FormatTSV      Format = "tsv"
)

Output format values.

func (*Format) UnmarshalText

func (f *Format) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type Store

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

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

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

Store saves and loads config.

type YAMLFileStore

type YAMLFileStore struct {
	// Path is the location of the config file
	Path string

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

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

YAMLFileStore provides persistence of config via YAML file.

func (*YAMLFileStore) FileExists

func (fs *YAMLFileStore) FileExists() bool

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

func (*YAMLFileStore) Load

func (fs *YAMLFileStore) Load() (*Config, error)

Load reads config from disk.

func (*YAMLFileStore) Location

func (fs *YAMLFileStore) Location() string

Location implements Store.

func (*YAMLFileStore) Save

func (fs *YAMLFileStore) Save(cfg *Config) error

Save writes config to disk.

func (*YAMLFileStore) String

func (fs *YAMLFileStore) String() string

Jump to

Keyboard shortcuts

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