config

package
v1.21.1 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2021 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BackupConfigFile = func(filename string) error {
	return os.Rename(filename, filename+".bak")
}

BackupConfigFile creates a backup of the provided config file

View Source
var LocalConfigDir = func() []string {
	return []string{".git", "glab-cli"}
}

LocalConfigDir returns the local config path in map which must be joined for complete path

View Source
var LocalConfigFile = func() string {
	configFile := append(LocalConfigDir(), "config.yml")
	return path.Join(configFile...)
}

LocalConfigFile returns the config file name with full path

View Source
var ReadConfigFile = func(filename string) ([]byte, error) {
	data, err := ioutil.ReadFile(filename)
	if err != nil {
		return nil, pathError(err)
	}

	return data, nil
}
View Source
var WriteConfigFile = func(filename string, data []byte) error {
	err := os.MkdirAll(path.Dir(filename), 0750)
	if err != nil {
		return pathError(err)
	}
	_, err = ioutil.ReadFile(filename)
	if err != nil && !os.IsNotExist(err) {
		return err
	}
	err = WriteFile(filename, data, 0600)
	return err
}

Functions

func CheckFileExists

func CheckFileExists(filename string) bool

CheckFileExists : checks if a file exists and is not a directory.

func CheckPathExists

func CheckPathExists(path string) bool

CheckPathExists checks if a folder exists and is a directory

func ConfigDir

func ConfigDir() string

ConfigDir returns the config directory

func ConfigFile

func ConfigFile() string

ConfigFile returns the config file path

func ConfigKeyEquivalence

func ConfigKeyEquivalence(key string) string

ConfigKeyEquivalence returns the equivalent key that's actually used in the config file

func EnvKeyEquivalence

func EnvKeyEquivalence(key string) []string

EnvKeyEquivalence returns the equivalent key that's used for environment variables

func GetFromEnv

func GetFromEnv(key string) (value string)

GetFromEnv is just a wrapper for os.GetEnv but checks for matching names used in previous glab versions and retrieves the value of the environment if any of the matching names has been set. It returns the value, which will be empty if the variable is not present.

func GetFromEnvWithSource added in v1.17.0

func GetFromEnvWithSource(key string) (value, source string)

func MigrateOldConfig

func MigrateOldConfig() error

MigrateOldConfig migrates the old aliases and configuration

func NewBlankRoot

func NewBlankRoot() *yaml.Node

func OldLocalConfigFile added in v1.20.0

func OldLocalConfigFile() string

OldLocalConfigFile returns the path to the old local config path.

func Prompt

func Prompt(question, defaultVal string) (envVal string, err error)

PromptAndSetEnv : prompts user for value and returns default value if empty

func StubConfig

func StubConfig(main, aliases string) func()

func StubWriteConfig

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

func WriteFile

func WriteFile(filename string, data []byte, perm os.FileMode) error

Types

type AliasConfig

type AliasConfig struct {
	ConfigMap
	Parent Config
}

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)

func (*AliasConfig) Set

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

func (*AliasConfig) Write

func (a *AliasConfig) Write() error

type Config

type Config interface {
	Get(string, string) (string, error)
	GetWithSource(string, string, bool) (string, string, error)
	Set(string, string, string) error
	UnsetHost(string)
	Hosts() ([]string, error)
	Aliases() (*AliasConfig, error)
	Local() (*LocalConfig, error)
	// Write writes to the config.yml file
	Write() error
	// WriteAll saves all the available configuration file types
	WriteAll() error
}

This interface describes interacting with some persistent configuration for glab.

func Init

func Init() (Config, error)

Init initialises and returns the cached configuration

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 ParseConfig

func ParseConfig(filename string) (Config, error)

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
}

ConfigMap 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 HostConfig

type HostConfig struct {
	ConfigMap
	Host string
}

type LocalConfig

type LocalConfig struct {
	ConfigMap
	Parent Config
}

func (*LocalConfig) All

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

func (*LocalConfig) Delete

func (a *LocalConfig) Delete(key string) error

func (*LocalConfig) Get

func (a *LocalConfig) Get(key string) (string, bool)

func (*LocalConfig) Set

func (a *LocalConfig) Set(key, value string) error

func (*LocalConfig) Write

func (a *LocalConfig) Write() error

type NotFoundError

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

Jump to

Keyboard shortcuts

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