config

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GH_CONFIG_DIR   = "GH_CONFIG_DIR"
	XDG_CONFIG_HOME = "XDG_CONFIG_HOME"
	XDG_STATE_HOME  = "XDG_STATE_HOME"
	XDG_DATA_HOME   = "XDG_DATA_HOME"
	APP_DATA        = "AppData"
	LOCAL_APP_DATA  = "LocalAppData"
)
View Source
const (
	GH_HOST                 = "GH_HOST"
	GH_TOKEN                = "GH_TOKEN"
	GITHUB_TOKEN            = "GITHUB_TOKEN"
	GH_ENTERPRISE_TOKEN     = "GH_ENTERPRISE_TOKEN"
	GITHUB_ENTERPRISE_TOKEN = "GITHUB_ENTERPRISE_TOKEN"
)

Variables

View Source
var BackupConfigFile = func(filename string) error {
	return os.Rename(filename, filename+".bak")
}
View Source
var ReadConfigFile = func(filename string) ([]byte, error) {
	f, err := os.Open(filename)
	if err != nil {
		return nil, pathError(err)
	}

	defer f.Close()

	data, err := ioutil.ReadAll(f)
	if err != nil {
		return nil, err
	}

	return data, nil
}
View Source
var WriteConfigFile = func(filename string, data []byte) error {
	err := os.MkdirAll(filepath.Dir(filename), 0771)
	if err != nil {
		return pathError(err)
	}

	cfgFile, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
	if err != nil {
		return err
	}

	defer cfgFile.Close()

	_, err = cfgFile.Write(data)
	return err
}

Functions

func AuthTokenFromEnv

func AuthTokenFromEnv(hostname string) (string, string)

func AuthTokenProvidedFromEnv

func AuthTokenProvidedFromEnv() bool

func ConfigDir

func ConfigDir() string

Config path precedence 1. GH_CONFIG_DIR 2. XDG_CONFIG_HOME 3. AppData (windows only) 4. HOME

func ConfigFile

func ConfigFile() string

func DataDir

func DataDir() string

Data path precedence 1. XDG_DATA_HOME 2. LocalAppData (windows only) 3. HOME

func HomeDirPath

func HomeDirPath(subdir string) (string, error)

func HostsConfigFile

func HostsConfigFile() string

func IsEnterpriseEnv

func IsEnterpriseEnv(src string) bool

func IsHostEnv

func IsHostEnv(src string) bool

func NewBlankRoot

func NewBlankRoot() *yaml.Node

func StateDir

func StateDir() string

State path precedence 1. XDG_STATE_HOME 2. LocalAppData (windows only) 3. HOME

func StubBackupConfig

func StubBackupConfig() func()

func StubWriteConfig

func StubWriteConfig(wc io.Writer, wh io.Writer) func()

func ValidateKey

func ValidateKey(key string) error

func ValidateValue

func ValidateValue(key, value string) error

Types

type AliasConfig

type AliasConfig struct {
	ConfigMap
	Parent Config
}

func (*AliasConfig) Add

func (a *AliasConfig) Add(alias, expansion string) error

func (*AliasConfig) All

func (a *AliasConfig) All() map[string]string

func (*AliasConfig) Delete

func (a *AliasConfig) Delete(alias string) error

func (*AliasConfig) Get

func (a *AliasConfig) Get(alias string) (string, bool)

type Config

type Config interface {
	Get(string, string) (string, error)
	GetWithSource(string, string) (string, string, error)
	Set(string, string, string) error
	UnsetHost(string)
	Hosts() ([]string, error)
	DefaultHost() (string, error)
	DefaultHostWithSource() (string, string, error)
	Aliases() (*AliasConfig, error)
	CheckWriteable(string, string) error
	Write() error
}

This interface describes interacting with some persistent configuration for gh.

func InheritEnv

func InheritEnv(c Config) Config

func NewBlankConfig

func NewBlankConfig() Config

NewBlankConfig initializes a config file pre-populated with comments and default values

func NewConfig

func NewConfig(root *yaml.Node) Config

func NewFromString

func NewFromString(str string) Config

NewFromString initializes a Config from a yaml string

func ParseDefaultConfig

func ParseDefaultConfig() (Config, error)

type ConfigEntry

type ConfigEntry struct {
	KeyNode   *yaml.Node
	ValueNode *yaml.Node
	Index     int
}

type ConfigMap

type ConfigMap struct {
	Root *yaml.Node
}

This type implements a low-level get/set config that is backed by an in-memory tree of Yaml nodes. It allows us to interact with a yaml-based config programmatically, preserving any comments that were present when the yaml was parsed.

func (*ConfigMap) Empty

func (cm *ConfigMap) Empty() bool

func (*ConfigMap) FindEntry

func (cm *ConfigMap) FindEntry(key string) (ce *ConfigEntry, err error)

func (*ConfigMap) GetStringValue

func (cm *ConfigMap) GetStringValue(key string) (string, error)

func (*ConfigMap) RemoveEntry

func (cm *ConfigMap) RemoveEntry(key string)

func (*ConfigMap) SetStringValue

func (cm *ConfigMap) SetStringValue(key, value string) error

type ConfigOption

type ConfigOption struct {
	Key           string
	Description   string
	DefaultValue  string
	AllowedValues []string
}

func ConfigOptions

func ConfigOptions() []ConfigOption

type ConfigStub

type ConfigStub map[string]string

func (ConfigStub) Aliases

func (c ConfigStub) Aliases() (*AliasConfig, error)

func (ConfigStub) CheckWriteable

func (c ConfigStub) CheckWriteable(host, key string) error

func (ConfigStub) DefaultHost

func (c ConfigStub) DefaultHost() (string, error)

func (ConfigStub) DefaultHostWithSource

func (c ConfigStub) DefaultHostWithSource() (string, string, error)

func (ConfigStub) Get

func (c ConfigStub) Get(host, key string) (string, error)

func (ConfigStub) GetWithSource

func (c ConfigStub) GetWithSource(host, key string) (string, string, error)

func (ConfigStub) Hosts

func (c ConfigStub) Hosts() ([]string, error)

func (ConfigStub) Set

func (c ConfigStub) Set(host, key, value string) error

func (ConfigStub) UnsetHost

func (c ConfigStub) UnsetHost(hostname string)

func (ConfigStub) Write

func (c ConfigStub) Write() error

type HostConfig

type HostConfig struct {
	ConfigMap
	Host string
}

type InvalidValueError

type InvalidValueError struct {
	ValidValues []string
}

func (InvalidValueError) Error

func (e InvalidValueError) Error() string

type NotFoundError

type NotFoundError struct {
	// contains filtered or unexported fields
}

type ReadOnlyEnvError

type ReadOnlyEnvError struct {
	Variable string
}

func (*ReadOnlyEnvError) Error

func (e *ReadOnlyEnvError) Error() string

Jump to

Keyboard shortcuts

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