Documentation
¶
Overview ¶
Package profile resolves which account identity gu should act as.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Candidates ¶ added in v0.14.1
func Candidates( resolved config.ProfileConfig, cfg config.Config, home, cwd string, ) []config.ProfileConfig
Candidates is the accounts to try when connecting, in order of preference: the profile Resolve chose, then the CLIs' own default, then every other account found on this machine.
The order is the point. Resolve picks the *most specific* configuration — a workspace's own .glab-cli, usually — and that is the right first guess. But a workspace directory that is logged out, or holds a token for somewhere else, should not hide the account the user is actually logged in to: it decides which account to prefer, not whether gu runs at all.
Only automatic detection falls back like this. Choosing an account by name through `:ctx` is a decision, and quietly connecting as a different one would be answering a question nobody asked.
func Resolve ¶
Resolve returns the profile that owns target. Precedence, first match wins:
- --profile flag
- declared profile whose Root is the longest path prefix of target
- .glab-cli directory or .envrc export found by walking up from target
- ambient GLAB_CONFIG_DIR / GH_CONFIG_DIR
- default_profile
"Nothing matched" is not an error: it yields a zero ProfileConfig, meaning gu should let glab and gh use their own default configuration.
Types ¶
type Account ¶
type Account struct {
Name string
GlabConfigDir string
GhConfigDir string
// Declared marks an account that came from config.yaml rather than from
// scanning the disk, so the UI can say which is which.
Declared bool
// CLIDefault marks the fallback account, which names no directory at all:
// glab and gh are left to use whatever they are configured with.
CLIDefault bool
}
Account is one CLI identity available on this machine: the glab and gh configuration directories that belong together, under a name.
A profile is its configuration directory, not its hostname — two accounts routinely share gitlab.com and are told apart only by which directory the CLI is pointed at.
func Accounts ¶
Accounts lists every identity gu can act as: the ones declared in config.yaml, plus every glab or gh configuration directory found on disk.
Discovery is what makes `:ctx` useful without configuration — the accounts are already on the machine, in the directories the CLIs were pointed at, and asking the user to declare them again in a second file would be asking twice. A declared profile still wins on name and on any directory it sets.
func (Account) Config ¶
func (a Account) Config() config.ProfileConfig
Config renders the account as the profile the rest of gu takes.