config

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GitProtocolFor added in v0.6.0

func GitProtocolFor(domain string) string

GitProtocolFor returns the configured git protocol ("https" or "ssh") for the given domain. Falls back to the default if not set for the domain. Returns "https" if not configured.

func ProjectConfigPath

func ProjectConfigPath() string

ProjectConfigPath walks up from the current directory looking for a .forge file. Returns empty string if none is found.

func ResetCache

func ResetCache()

ResetCache clears the cached config. Only useful in tests.

func SetDomain

func SetDomain(domain, token, tokenCmd, forgeType string) error

SetDomain updates or adds a domain section in the user config file. Creates the config directory if needed. Sets file permissions to 0600 since the file may contain tokens.

func UserConfigPath

func UserConfigPath() string

UserConfigPath returns the path to the user-level config file. It respects XDG_CONFIG_HOME, falling back to ~/.config/forge/config.

Types

type Config

type Config struct {
	Default DefaultSection
	Domains map[string]DomainSection
}

func Load

func Load() (*Config, error)

Load returns the merged config from both user and project config files. The result is cached so the files are parsed at most once per invocation.

func (*Config) DomainForSSHHost added in v0.4.0

func (c *Config) DomainForSSHHost(sshHost string) string

DomainForSSHHost returns the API domain (the section name) whose ssh_host matches the given host, or "" if none. Self-hosted GitLab in particular can serve git-over-ssh on a different host than the web/API, so a remote URL like git@ssh.gitlab.test:owner/repo needs mapping back to gitlab.test before we build an API client.

type DefaultSection

type DefaultSection struct {
	Output      string // table, json, plain
	ForgeType   string // default forge type
	GitProtocol string // https or ssh
}

type DomainSection

type DomainSection struct {
	Type        string // github, gitlab, gitea, forgejo, bitbucket, gerrit, tangled
	Token       string // resolved token value; only from user config, never .forge
	TokenExec   string // non-empty when token is retrieved via a shell command (from "token-cmd" config key)
	SSHHost     string // alternate host for git-over-ssh; the section name remains the API host
	GitProtocol string // https or ssh; overrides default
}

func (DomainSection) ResolveToken added in v0.7.0

func (ds DomainSection) ResolveToken(domain string) (string, error)

ResolveToken returns the token for this domain. If TokenExec is set, it executes the command and returns its output; otherwise it returns Token.

Jump to

Keyboard shortcuts

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