Documentation
¶
Index ¶
- Constants
- Variables
- func AuthTokenFromEnv(hostname string) (string, string)
- func AuthTokenProvidedFromEnv() bool
- func DataDir() string
- func Dir() string
- func File() string
- func HomeDirPath(subdir string) (string, error)
- func HostsConfigFile() string
- func IsHostEnv(src string) bool
- func NewBlankRoot() *yaml.Node
- func StateDir() string
- func StubBackupConfig() func()
- func StubWriteConfig(wc io.Writer, wh io.Writer) func()
- func ValidateKey(key string) error
- func ValidateValue(key, value string) error
- type AliasConfig
- type Config
- type Entry
- type HostConfig
- type InvalidValueError
- type Map
- type NotFoundError
- type Option
- type ReadOnlyEnvError
- type Stub
- func (c Stub) Aliases() (*AliasConfig, error)
- func (c Stub) CheckWriteable(host, key string) error
- func (c Stub) DefaultHost() (string, error)
- func (c Stub) DefaultHostWithSource() (string, string, error)
- func (c Stub) Get(host, key string) (string, error)
- func (c Stub) GetWithSource(host, key string) (string, string, error)
- func (c Stub) Hosts() ([]string, error)
- func (c Stub) Set(host, key, value string) error
- func (c Stub) UnsetHost(hostname string)
- func (c Stub) Write() error
Constants ¶
const ( // KittyCADConfigDirEnvVar is the environment variable that can be used to override // the default config directory. KittyCADConfigDirEnvVar = "KITTYCAD_CONFIG_DIR" // KittyCADShorthandDir is the directory name used for the config and state. KittyCADShorthandDir = "kittycad" // KittyCADWindowsDir is the directory name used for the config and state on Windows.` KittyCADWindowsDir = "KittyCAD CLI" // XDGConfigHomeEnvVar is the environment variable for the XDG_CONFIG_HOME. XDGConfigHomeEnvVar = "XDG_CONFIG_HOME" // XDGStateHomeEnvVar is the environment variable for the XDG_STATE_HOME. XDGStateHomeEnvVar = "XDG_STATE_HOME" // XDGDataHomeEnvVar is the environment variable for the XDG_DATA_HOME. XDGDataHomeEnvVar = "XDG_DATA_HOME" // AppData is the directory for AppData on Windows. AppData = "AppData" // LocalAppData is the directory for LocalAppData on Windows. LocalAppData = "LocalAppData" )
const ( // KittyCADHostEnvVar is the environment variable name for the host. KittyCADHostEnvVar = "KITTYCAD_HOST" // KittyCADTokenEnvVar is the environment variable name for the token. KittyCADTokenEnvVar = "KITTYCAD_TOKEN" // KittyCADAPITokenEnvVar is the environment variable name for the API token. KittyCADAPITokenEnvVar = "KITTYCAD_API_TOKEN" // KittyCADDefaultHost is the default host. KittyCADDefaultHost = "api.kittycad.io" )
Variables ¶
var BackupConfigFile = func(filename string) error { return os.Rename(filename, filename+".bak") }
BackupConfigFile backs up the config file.
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 }
ReadConfigFile reads the config file.
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 }
WriteConfigFile writes the config file.
Functions ¶
func AuthTokenFromEnv ¶
AuthTokenFromEnv returns the auth token and the environment variable name.
func AuthTokenProvidedFromEnv ¶
func AuthTokenProvidedFromEnv() bool
AuthTokenProvidedFromEnv returns true if the auth token is provided.
func DataDir ¶
func DataDir() string
DataDir returns the path to the data directory. Data path precedence 1. XDG_DATA_HOME 2. LocalAppData (windows only) 3. HOME
func Dir ¶
func Dir() string
Dir returns the path to the config directory. Config path precedence 1. KITTYCAD_CONFIG_DIR 2. XDG_CONFIG_HOME 3. AppData (windows only) 4. HOME
func HomeDirPath ¶
HomeDirPath returns the path to the home directory.
func HostsConfigFile ¶
func HostsConfigFile() string
HostsConfigFile returns the path to the hosts config file.
func NewBlankRoot ¶
func NewBlankRoot() *yaml.Node
NewBlankRoot initializes a config file pre-populated with comments and default values.
func StateDir ¶
func StateDir() string
StateDir returns the path to the state directory. State path precedence 1. XDG_CONFIG_HOME 2. LocalAppData (windows only) 3. HOME
func StubBackupConfig ¶
func StubBackupConfig() func()
StubBackupConfig stubs the backup config file.
func StubWriteConfig ¶
StubWriteConfig stubs the write config file.
func ValidateValue ¶
ValidateValue validates a value for a key.
Types ¶
type AliasConfig ¶
AliasConfig is a config file that stores aliases.
func (*AliasConfig) Add ¶
func (a *AliasConfig) Add(alias, expansion string) error
Add adds an alias to the config.
func (*AliasConfig) All ¶
func (a *AliasConfig) All() map[string]string
All returns all aliases in the config.
func (*AliasConfig) Delete ¶
func (a *AliasConfig) Delete(alias string) error
Delete deletes an alias from the config.
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 }
Config is the interface for a configuration file.
func InheritEnv ¶
InheritEnv returns true if the environment variable is inherited.
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
NewConfig initializes a Config from a yaml node.
func NewFromString ¶
NewFromString initializes a Config from a yaml string.
func ParseDefaultConfig ¶
ParseDefaultConfig parses the default config file.
type Entry ¶
type Entry struct { KeyNode *yaml.Node ValueNode *yaml.Node Index int }
Entry represents a single entry in a Map.
type HostConfig ¶
HostConfig represents a single host entry in the hosts.yml file.
type InvalidValueError ¶
type InvalidValueError struct {
ValidValues []string
}
InvalidValueError is an error that occurs when a value is not valid for a key.
func (InvalidValueError) Error ¶
func (e InvalidValueError) Error() string
Error implements the error interface.
type Map ¶
type Map struct {
Root *yaml.Node
}
Map 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 (*Map) GetStringValue ¶
GetStringValue returns the value of the given key as a string.
func (*Map) RemoveEntry ¶
RemoveEntry removes the entry with the given key.
func (*Map) SetStringValue ¶
SetStringValue sets the value of the given key to the given string.
type NotFoundError ¶
type NotFoundError struct {
// contains filtered or unexported fields
}
NotFoundError is returned when a key is not found in a Map.
type ReadOnlyEnvError ¶
type ReadOnlyEnvError struct {
Variable string
}
ReadOnlyEnvError is an error that is returned when an environment is read only.
func (*ReadOnlyEnvError) Error ¶
func (e *ReadOnlyEnvError) Error() string
Error returns a string representation of the error.
type Stub ¶
Stub is a stub implementation of the Config interface.
func (Stub) Aliases ¶
func (c Stub) Aliases() (*AliasConfig, error)
Aliases returns the aliases of the given key.
func (Stub) CheckWriteable ¶
CheckWriteable checks if the config is writeable.
func (Stub) DefaultHost ¶
DefaultHost returns the default host.
func (Stub) DefaultHostWithSource ¶
DefaultHostWithSource returns the default host.
func (Stub) GetWithSource ¶
GetWithSource returns the value of the given key.