config

package
v2.11.1 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: MIT Imports: 8 Imported by: 11

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

View Source
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.

func StateDir

func StateDir() string

State path precedence: XDG_STATE_HOME, LocalAppData (windows only), HOME.

func Write

func Write(c *Config) error

Write gh configuration files to the local file system. It will only write gh configuration files that have been modified since last being read.

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

func ReadFromString(str string) *Config

ReadFromString takes a yaml string and returns a Config.

func (*Config) Get

func (c *Config) Get(keys []string) (string, error)

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

func (c *Config) Keys(keys []string) ([]string, error)

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

func (c *Config) Remove(keys []string) error

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

func (c *Config) Set(keys []string, value string)

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

type InvalidConfigFileError struct {
	Path string
	Err  error
}

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.

Jump to

Keyboard shortcuts

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