config

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

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

	return data, nil
}
View Source
var WriteConfigFile = func(fn string, data []byte) error {
	cfgFile, err := os.OpenFile(ConfigFile(), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
	if err != nil {
		return err
	}
	defer cfgFile.Close()

	n, err := cfgFile.Write(data)
	if err == nil && n < len(data) {
		err = io.ErrShortWrite
	}

	return err
}

Functions

func AuthFlow added in v0.8.0

func AuthFlow(notice string) (string, string, error)

func AuthFlowComplete added in v0.8.0

func AuthFlowComplete()

func ConfigDir

func ConfigDir() string

func ConfigFile

func ConfigFile() string

func IsGitHubApp added in v0.8.0

func IsGitHubApp(id string) bool

IsGitHubApp reports whether an OAuth app is "GitHub CLI" or "GitHub CLI (dev)"

func StubBackupConfig

func StubBackupConfig() func()

func StubConfig

func StubConfig(content string) func()

func StubWriteConfig

func StubWriteConfig(w io.Writer) func()

Types

type Config

type Config interface {
	Hosts() ([]*HostConfig, error)
	Get(string, string) (string, error)
	Set(string, string, string) error
	Write() error
}

This interface describes interacting with some persistent configuration for gh.

func NewConfig

func NewConfig(root *yaml.Node) Config

func ParseConfig

func ParseConfig(fn string) (Config, error)

func ParseDefaultConfig

func ParseDefaultConfig() (Config, error)

func ParseOrSetupConfigFile

func ParseOrSetupConfigFile(fn string) (Config, error)

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 waas parsed.

func (*ConfigMap) FindEntry

func (cm *ConfigMap) FindEntry(key string) (keyNode, valueNode *yaml.Node, err error)

func (*ConfigMap) GetStringValue

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

func (*ConfigMap) SetStringValue

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

type HostConfig

type HostConfig struct {
	ConfigMap
	Host string
}

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