Documentation ¶
Overview ¶
Package config is a set of types for interacting with the gh configuration files. Note: This package is intended for use only in gh, any other use cases are subject to breakage and non-backwards compatible updates.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Read = func(fallback *Config) (*Config, error) {
once.Do(func() {
cfg, loadErr = load(generalConfigFile(), hostsConfigFile(), fallback)
})
return cfg, loadErr
}
Read gh configuration files from the local file system and returns a Config. A copy of the fallback configuration will be returned when there are no configuration files to load. If there are no configuration files and no fallback configuration an empty configuration will be returned.
Functions ¶
func CacheDir ¶ added in v2.2.0
func CacheDir() string
Cache path precedence: XDG_CACHE_HOME, LocalAppData (windows only), HOME, legacy gh-cli-cache.
func ConfigDir ¶
func ConfigDir() string
Config path precedence: GH_CONFIG_DIR, XDG_CONFIG_HOME, AppData (windows only), HOME.
func DataDir ¶
func DataDir() string
Data path precedence: XDG_DATA_HOME, LocalAppData (windows only), HOME.
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config is a in memory representation of the gh configuration files. It can be thought of as map where entries consist of a key that correspond to either a string value or a map value, allowing for multi-level maps.
func ReadFromString ¶
ReadFromString takes a yaml string and returns a Config.
func (*Config) Get ¶
Get a string value from a Config. The keys argument is a sequence of key values so that nested entries can be retrieved. A undefined string will be returned if trying to retrieve a key that corresponds to a map value. Returns "", KeyNotFoundError if any of the keys can not be found.
func (*Config) Keys ¶
Keys enumerates a Config's keys. The keys argument is a sequence of key values so that nested map values can be have their keys enumerated. Returns nil, KeyNotFoundError if any of the keys can not be found.
func (*Config) Remove ¶
Remove an entry from a Config. The keys argument is a sequence of key values so that nested entries can be removed. Removing an entry that has nested entries removes those also. Returns KeyNotFoundError if any of the keys can not be found.
func (*Config) Set ¶
Set a string value in a Config. The keys argument is a sequence of key values so that nested entries can be set. If any of the keys do not exist they will be created. If the string value to be set is empty it will be represented as null not an empty string when written.
var c *Config c.Set([]string{"key"}, "") Write(c) // writes `key: ` not `key: ""`
type InvalidConfigFileError ¶
InvalidConfigFileError represents an error when trying to read a config file.
func (*InvalidConfigFileError) Error ¶
func (e *InvalidConfigFileError) Error() string
Allow InvalidConfigFileError to satisfy error interface.
func (*InvalidConfigFileError) Unwrap ¶
func (e *InvalidConfigFileError) Unwrap() error
Allow InvalidConfigFileError to be unwrapped.
type KeyNotFoundError ¶
type KeyNotFoundError struct {
Key string
}
KeyNotFoundError represents an error when trying to find a config key that does not exist.
func (*KeyNotFoundError) Error ¶
func (e *KeyNotFoundError) Error() string
Allow KeyNotFoundError to satisfy error interface.