Documentation
¶
Overview ¶
Package config resolves CLI configuration from flags, environment, and the config file. Only non-secret settings live in the file; tokens go to the OS keychain.
Index ¶
Constants ¶
const DefaultOutputFormat = "human"
DefaultOutputFormat is used when neither flag nor config file names one.
const FileName = "cli.yaml"
FileName is the config file name relative to ~/.config.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
AssetsWebURL string
Output string
// BaseURL is the config file's baseURL - every service.<service> entry
// in the config file is a path resolved against it (e.g. baseURL
// "https://dev.sweetrpg.com" + services.catalog "/api/0/catalog").
BaseURL string
// Services holds each configured service's path override from the
// config file, keyed by its camelCase service name (e.g. "gameRoom"),
// resolved against BaseURL. An env var or flag override is always a
// full URL instead - see ServiceURL.
Services map[string]string
// FilePath is the resolved config file path, or "" when no home
// directory is available.
FilePath string
// AuthDomain, AuthClientID, and AuthAudience are the config file's
// authTenant section, letting an operator repoint the Auth0 tenant
// without a rebuild. See auth.ResolveConfig for the full precedence.
AuthDomain string
AuthClientID string
AuthAudience string
}
Config holds resolved settings for one command run.
func Load ¶
Load resolves configuration by precedence: flag > environment > config file. Per-service base URLs are validated lazily via Config.ServiceURL, not here, since which services a given command run needs varies by command.
func (*Config) ServiceURL ¶
func (c *Config) ServiceURL(getenv func(string) string, flagOverride, service string) (string, error)
ServiceURL resolves a named service's base URL by precedence: flagOverride (a command's own --api-url flag, if it has one) > the service's SWEETRPG_<SERVICE>_API_URL environment variable, both taken as a full URL > the config file's services.<service> entry, taken as a path and resolved against BaseURL. service is given in kebab-case (e.g. "game-room"); the config file key is its camelCase form ("gameRoom"). SWEETRPG_CATALOG_API_URL is preserved as the env var name for "catalog".