Documentation
¶
Index ¶
- func ConfigDir() string
- func DataDir() string
- func HomeDirPath(subdir string) (string, error)
- func StateDir() string
- func StubWriteConfig(t *testing.T) func(io.Writer, io.Writer)
- type AliasConfig
- type AuthConfig
- func (c *AuthConfig) ActiveToken(hostname string) (string, string)
- func (c *AuthConfig) ActiveUser(hostname string) (string, error)
- func (c *AuthConfig) DefaultHost() (string, string)
- func (c *AuthConfig) HasEnvToken() bool
- func (c *AuthConfig) Hosts() []string
- func (c *AuthConfig) Login(hostname, username, token, gitProtocol string, secureStorage bool) (bool, error)
- func (c *AuthConfig) Logout(hostname, username string) error
- func (c *AuthConfig) SetActiveToken(token, source string)
- func (c *AuthConfig) SetDefaultHost(host, source string)
- func (c *AuthConfig) SetHosts(hosts []string)
- func (c *AuthConfig) SwitchUser(hostname, user string) error
- func (c *AuthConfig) TokenForUser(hostname, user string) (string, string, error)
- func (c *AuthConfig) TokenFromKeyring(hostname string) (string, error)
- func (c *AuthConfig) TokenFromKeyringForUser(hostname, username string) (string, error)
- func (c *AuthConfig) UsersForHost(hostname string) []string
- type Config
- type ConfigMock
- func (mock *ConfigMock) Aliases() *AliasConfig
- func (mock *ConfigMock) AliasesCalls() []struct{}
- func (mock *ConfigMock) Authentication() *AuthConfig
- func (mock *ConfigMock) AuthenticationCalls() []struct{}
- func (mock *ConfigMock) Browser(s string) string
- func (mock *ConfigMock) BrowserCalls() []struct{ ... }
- func (mock *ConfigMock) Editor(s string) string
- func (mock *ConfigMock) EditorCalls() []struct{ ... }
- func (mock *ConfigMock) GetOrDefault(s1 string, s2 string) (string, error)
- func (mock *ConfigMock) GetOrDefaultCalls() []struct{ ... }
- func (mock *ConfigMock) GitProtocol(s string) string
- func (mock *ConfigMock) GitProtocolCalls() []struct{ ... }
- func (mock *ConfigMock) HTTPUnixSocket(s string) string
- func (mock *ConfigMock) HTTPUnixSocketCalls() []struct{ ... }
- func (mock *ConfigMock) Migrate(migration Migration) error
- func (mock *ConfigMock) MigrateCalls() []struct{ ... }
- func (mock *ConfigMock) Pager(s string) string
- func (mock *ConfigMock) PagerCalls() []struct{ ... }
- func (mock *ConfigMock) Prompt(s string) string
- func (mock *ConfigMock) PromptCalls() []struct{ ... }
- func (mock *ConfigMock) Set(s1 string, s2 string, s3 string)
- func (mock *ConfigMock) SetCalls() []struct{ ... }
- func (mock *ConfigMock) Version() string
- func (mock *ConfigMock) VersionCalls() []struct{}
- func (mock *ConfigMock) Write() error
- func (mock *ConfigMock) WriteCalls() []struct{}
- type ConfigOption
- type Migration
- type MigrationMock
- func (mock *MigrationMock) Do(config *ghConfig.Config) error
- func (mock *MigrationMock) DoCalls() []struct{ ... }
- func (mock *MigrationMock) PostVersion() string
- func (mock *MigrationMock) PostVersionCalls() []struct{}
- func (mock *MigrationMock) PreVersion() string
- func (mock *MigrationMock) PreVersionCalls() []struct{}
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HomeDirPath ¶
func StubWriteConfig ¶
StubWriteConfig stubs out the filesystem where config file are written. It then returns a function that will read in the config files into io.Writers. It automatically cleans up environment variables and written files.
Types ¶
type AliasConfig ¶
type AliasConfig struct {
// contains filtered or unexported fields
}
func (*AliasConfig) Add ¶
func (a *AliasConfig) Add(alias, expansion string)
func (*AliasConfig) All ¶
func (a *AliasConfig) All() map[string]string
func (*AliasConfig) Delete ¶
func (a *AliasConfig) Delete(alias string) error
type AuthConfig ¶ added in v2.24.0
type AuthConfig struct {
// contains filtered or unexported fields
}
AuthConfig is used for interacting with some persistent configuration for gh, with knowledge on how to access encrypted storage when neccesarry. Behavior is scoped to authentication specific tasks.
func (*AuthConfig) ActiveToken ¶ added in v2.40.0
func (c *AuthConfig) ActiveToken(hostname string) (string, string)
ActiveToken will retrieve the active auth token for the given hostname, searching environment variables, plain text config, and lastly encrypted storage.
func (*AuthConfig) ActiveUser ¶ added in v2.40.0
func (c *AuthConfig) ActiveUser(hostname string) (string, error)
ActiveUser will retrieve the username for the active user at the given hostname. This will not be accurate if the oauth token is set from an environment variable.
func (*AuthConfig) DefaultHost ¶ added in v2.24.0
func (c *AuthConfig) DefaultHost() (string, string)
func (*AuthConfig) HasEnvToken ¶ added in v2.25.0
func (c *AuthConfig) HasEnvToken() bool
HasEnvToken returns true when a token has been specified in an environment variable, else returns false.
func (*AuthConfig) Hosts ¶ added in v2.24.0
func (c *AuthConfig) Hosts() []string
func (*AuthConfig) Login ¶ added in v2.24.0
func (c *AuthConfig) Login(hostname, username, token, gitProtocol string, secureStorage bool) (bool, error)
Login will set user, git protocol, and auth token for the given hostname. If the encrypt option is specified it will first try to store the auth token in encrypted storage and will fall back to the plain text config file.
func (*AuthConfig) Logout ¶ added in v2.24.0
func (c *AuthConfig) Logout(hostname, username string) error
Logout will remove user, git protocol, and auth token for the given hostname. It will remove the auth token from the encrypted storage if it exists there.
func (*AuthConfig) SetActiveToken ¶ added in v2.40.0
func (c *AuthConfig) SetActiveToken(token, source string)
SetActiveToken will override any token resolution and return the given token and source for all calls to ActiveToken. Use for testing purposes only.
func (*AuthConfig) SetDefaultHost ¶ added in v2.24.0
func (c *AuthConfig) SetDefaultHost(host, source string)
SetDefaultHost will override any host resolution and return the given host and source for all calls to DefaultHost. Use for testing purposes only.
func (*AuthConfig) SetHosts ¶ added in v2.24.0
func (c *AuthConfig) SetHosts(hosts []string)
SetHosts will override any hosts resolution and return the given hosts for all calls to Hosts. Use for testing purposes only.
func (*AuthConfig) SwitchUser ¶ added in v2.40.0
func (c *AuthConfig) SwitchUser(hostname, user string) error
func (*AuthConfig) TokenForUser ¶ added in v2.40.0
func (c *AuthConfig) TokenForUser(hostname, user string) (string, string, error)
func (*AuthConfig) TokenFromKeyring ¶ added in v2.24.0
func (c *AuthConfig) TokenFromKeyring(hostname string) (string, error)
TokenFromKeyring will retrieve the auth token for the given hostname, only searching in encrypted storage.
func (*AuthConfig) TokenFromKeyringForUser ¶ added in v2.40.0
func (c *AuthConfig) TokenFromKeyringForUser(hostname, username string) (string, error)
TokenFromKeyringForUser will retrieve the auth token for the given hostname and username, only searching in encrypted storage.
An empty username will return an error because the potential to return the currently active token under surprising cases is just too high to risk compared to the utility of having the function being smart.
func (*AuthConfig) UsersForHost ¶ added in v2.40.0
func (c *AuthConfig) UsersForHost(hostname string) []string
type Config ¶
type Config interface { GetOrDefault(string, string) (string, error) Set(string, string, string) Write() error Migrate(Migration) error Aliases() *AliasConfig Authentication() *AuthConfig Browser(string) string Editor(string) string GitProtocol(string) string HTTPUnixSocket(string) string Pager(string) string Prompt(string) string Version() string }
This interface describes interacting with some persistent configuration for gh.
func NewIsolatedTestConfig ¶ added in v2.40.0
NewIsolatedTestConfig sets up a Mock keyring, creates a blank config overwrites the ghConfig.Read function that returns a singleton config in the real implementation, sets the GH_CONFIG_DIR env var so that any call to Write goes to a different location on disk, and then returns the blank config and a function that reads any data written to disk.
type ConfigMock ¶ added in v2.14.0
type ConfigMock struct { // AliasesFunc mocks the Aliases method. AliasesFunc func() *AliasConfig // AuthenticationFunc mocks the Authentication method. AuthenticationFunc func() *AuthConfig // BrowserFunc mocks the Browser method. BrowserFunc func(s string) string // EditorFunc mocks the Editor method. EditorFunc func(s string) string // GetOrDefaultFunc mocks the GetOrDefault method. GetOrDefaultFunc func(s1 string, s2 string) (string, error) // GitProtocolFunc mocks the GitProtocol method. GitProtocolFunc func(s string) string // HTTPUnixSocketFunc mocks the HTTPUnixSocket method. HTTPUnixSocketFunc func(s string) string // MigrateFunc mocks the Migrate method. MigrateFunc func(migration Migration) error // PagerFunc mocks the Pager method. PagerFunc func(s string) string // PromptFunc mocks the Prompt method. PromptFunc func(s string) string // SetFunc mocks the Set method. SetFunc func(s1 string, s2 string, s3 string) // VersionFunc mocks the Version method. VersionFunc func() string // WriteFunc mocks the Write method. WriteFunc func() error // contains filtered or unexported fields }
ConfigMock is a mock implementation of Config.
func TestSomethingThatUsesConfig(t *testing.T) { // make and configure a mocked Config mockedConfig := &ConfigMock{ AliasesFunc: func() *AliasConfig { panic("mock out the Aliases method") }, AuthenticationFunc: func() *AuthConfig { panic("mock out the Authentication method") }, BrowserFunc: func(s string) string { panic("mock out the Browser method") }, EditorFunc: func(s string) string { panic("mock out the Editor method") }, GetOrDefaultFunc: func(s1 string, s2 string) (string, error) { panic("mock out the GetOrDefault method") }, GitProtocolFunc: func(s string) string { panic("mock out the GitProtocol method") }, HTTPUnixSocketFunc: func(s string) string { panic("mock out the HTTPUnixSocket method") }, MigrateFunc: func(migration Migration) error { panic("mock out the Migrate method") }, PagerFunc: func(s string) string { panic("mock out the Pager method") }, PromptFunc: func(s string) string { panic("mock out the Prompt method") }, SetFunc: func(s1 string, s2 string, s3 string) { panic("mock out the Set method") }, VersionFunc: func() string { panic("mock out the Version method") }, WriteFunc: func() error { panic("mock out the Write method") }, } // use mockedConfig in code that requires Config // and then make assertions. }
func NewBlankConfig ¶
func NewBlankConfig() *ConfigMock
func NewFromString ¶
func NewFromString(cfgStr string) *ConfigMock
func (*ConfigMock) Aliases ¶ added in v2.14.0
func (mock *ConfigMock) Aliases() *AliasConfig
Aliases calls AliasesFunc.
func (*ConfigMock) AliasesCalls ¶ added in v2.14.0
func (mock *ConfigMock) AliasesCalls() []struct { }
AliasesCalls gets all the calls that were made to Aliases. Check the length with:
len(mockedConfig.AliasesCalls())
func (*ConfigMock) Authentication ¶ added in v2.24.0
func (mock *ConfigMock) Authentication() *AuthConfig
Authentication calls AuthenticationFunc.
func (*ConfigMock) AuthenticationCalls ¶ added in v2.24.0
func (mock *ConfigMock) AuthenticationCalls() []struct { }
AuthenticationCalls gets all the calls that were made to Authentication. Check the length with:
len(mockedConfig.AuthenticationCalls())
func (*ConfigMock) Browser ¶ added in v2.38.0
func (mock *ConfigMock) Browser(s string) string
Browser calls BrowserFunc.
func (*ConfigMock) BrowserCalls ¶ added in v2.38.0
func (mock *ConfigMock) BrowserCalls() []struct { S string }
BrowserCalls gets all the calls that were made to Browser. Check the length with:
len(mockedConfig.BrowserCalls())
func (*ConfigMock) Editor ¶ added in v2.38.0
func (mock *ConfigMock) Editor(s string) string
Editor calls EditorFunc.
func (*ConfigMock) EditorCalls ¶ added in v2.38.0
func (mock *ConfigMock) EditorCalls() []struct { S string }
EditorCalls gets all the calls that were made to Editor. Check the length with:
len(mockedConfig.EditorCalls())
func (*ConfigMock) GetOrDefault ¶ added in v2.14.0
func (mock *ConfigMock) GetOrDefault(s1 string, s2 string) (string, error)
GetOrDefault calls GetOrDefaultFunc.
func (*ConfigMock) GetOrDefaultCalls ¶ added in v2.14.0
func (mock *ConfigMock) GetOrDefaultCalls() []struct { S1 string S2 string }
GetOrDefaultCalls gets all the calls that were made to GetOrDefault. Check the length with:
len(mockedConfig.GetOrDefaultCalls())
func (*ConfigMock) GitProtocol ¶ added in v2.38.0
func (mock *ConfigMock) GitProtocol(s string) string
GitProtocol calls GitProtocolFunc.
func (*ConfigMock) GitProtocolCalls ¶ added in v2.38.0
func (mock *ConfigMock) GitProtocolCalls() []struct { S string }
GitProtocolCalls gets all the calls that were made to GitProtocol. Check the length with:
len(mockedConfig.GitProtocolCalls())
func (*ConfigMock) HTTPUnixSocket ¶ added in v2.38.0
func (mock *ConfigMock) HTTPUnixSocket(s string) string
HTTPUnixSocket calls HTTPUnixSocketFunc.
func (*ConfigMock) HTTPUnixSocketCalls ¶ added in v2.38.0
func (mock *ConfigMock) HTTPUnixSocketCalls() []struct { S string }
HTTPUnixSocketCalls gets all the calls that were made to HTTPUnixSocket. Check the length with:
len(mockedConfig.HTTPUnixSocketCalls())
func (*ConfigMock) Migrate ¶ added in v2.40.0
func (mock *ConfigMock) Migrate(migration Migration) error
Migrate calls MigrateFunc.
func (*ConfigMock) MigrateCalls ¶ added in v2.40.0
func (mock *ConfigMock) MigrateCalls() []struct { Migration Migration }
MigrateCalls gets all the calls that were made to Migrate. Check the length with:
len(mockedConfig.MigrateCalls())
func (*ConfigMock) Pager ¶ added in v2.38.0
func (mock *ConfigMock) Pager(s string) string
Pager calls PagerFunc.
func (*ConfigMock) PagerCalls ¶ added in v2.38.0
func (mock *ConfigMock) PagerCalls() []struct { S string }
PagerCalls gets all the calls that were made to Pager. Check the length with:
len(mockedConfig.PagerCalls())
func (*ConfigMock) Prompt ¶ added in v2.38.0
func (mock *ConfigMock) Prompt(s string) string
Prompt calls PromptFunc.
func (*ConfigMock) PromptCalls ¶ added in v2.38.0
func (mock *ConfigMock) PromptCalls() []struct { S string }
PromptCalls gets all the calls that were made to Prompt. Check the length with:
len(mockedConfig.PromptCalls())
func (*ConfigMock) Set ¶ added in v2.14.0
func (mock *ConfigMock) Set(s1 string, s2 string, s3 string)
Set calls SetFunc.
func (*ConfigMock) SetCalls ¶ added in v2.14.0
func (mock *ConfigMock) SetCalls() []struct { S1 string S2 string S3 string }
SetCalls gets all the calls that were made to Set. Check the length with:
len(mockedConfig.SetCalls())
func (*ConfigMock) Version ¶ added in v2.40.0
func (mock *ConfigMock) Version() string
Version calls VersionFunc.
func (*ConfigMock) VersionCalls ¶ added in v2.40.0
func (mock *ConfigMock) VersionCalls() []struct { }
VersionCalls gets all the calls that were made to Version. Check the length with:
len(mockedConfig.VersionCalls())
func (*ConfigMock) Write ¶ added in v2.14.0
func (mock *ConfigMock) Write() error
Write calls WriteFunc.
func (*ConfigMock) WriteCalls ¶ added in v2.14.0
func (mock *ConfigMock) WriteCalls() []struct { }
WriteCalls gets all the calls that were made to Write. Check the length with:
len(mockedConfig.WriteCalls())
type ConfigOption ¶
type ConfigOption struct { Key string Description string DefaultValue string AllowedValues []string }
func ConfigOptions ¶
func ConfigOptions() []ConfigOption
type Migration ¶ added in v2.40.0
type Migration interface { // PreVersion is the required config version for this to be applied PreVersion() string // PostVersion is the config version that must be applied after migration PostVersion() string // Do is expected to apply any necessary changes to the config in place Do(*ghConfig.Config) error }
Migration is the interface that config migrations must implement.
Migrations will receive a copy of the config, and should modify that copy as necessary. After migration has completed, the modified config contents will be used.
The calling code is expected to verify that the current version of the config matches the PreVersion of the migration before calling Do, and will set the config version to the PostVersion after the migration has completed successfully.
type MigrationMock ¶ added in v2.40.0
type MigrationMock struct { // DoFunc mocks the Do method. DoFunc func(config *ghConfig.Config) error // PostVersionFunc mocks the PostVersion method. PostVersionFunc func() string // PreVersionFunc mocks the PreVersion method. PreVersionFunc func() string // contains filtered or unexported fields }
MigrationMock is a mock implementation of Migration.
func TestSomethingThatUsesMigration(t *testing.T) { // make and configure a mocked Migration mockedMigration := &MigrationMock{ DoFunc: func(config *ghConfig.Config) error { panic("mock out the Do method") }, PostVersionFunc: func() string { panic("mock out the PostVersion method") }, PreVersionFunc: func() string { panic("mock out the PreVersion method") }, } // use mockedMigration in code that requires Migration // and then make assertions. }
func (*MigrationMock) Do ¶ added in v2.40.0
func (mock *MigrationMock) Do(config *ghConfig.Config) error
Do calls DoFunc.
func (*MigrationMock) DoCalls ¶ added in v2.40.0
func (mock *MigrationMock) DoCalls() []struct { Config *ghConfig.Config }
DoCalls gets all the calls that were made to Do. Check the length with:
len(mockedMigration.DoCalls())
func (*MigrationMock) PostVersion ¶ added in v2.40.0
func (mock *MigrationMock) PostVersion() string
PostVersion calls PostVersionFunc.
func (*MigrationMock) PostVersionCalls ¶ added in v2.40.0
func (mock *MigrationMock) PostVersionCalls() []struct { }
PostVersionCalls gets all the calls that were made to PostVersion. Check the length with:
len(mockedMigration.PostVersionCalls())
func (*MigrationMock) PreVersion ¶ added in v2.40.0
func (mock *MigrationMock) PreVersion() string
PreVersion calls PreVersionFunc.
func (*MigrationMock) PreVersionCalls ¶ added in v2.40.0
func (mock *MigrationMock) PreVersionCalls() []struct { }
PreVersionCalls gets all the calls that were made to PreVersion. Check the length with:
len(mockedMigration.PreVersionCalls())