Documentation
¶
Overview ¶
Package config loads and persists the Hostim CLI configuration and resolves the effective token, API URL and current project from flags, environment and the on-disk config file.
Index ¶
Constants ¶
const ( EnvToken = "HOSTIM_TOKEN" EnvAPIURL = "HOSTIM_API_URL" EnvProject = "HOSTIM_PROJECT" )
Env var names recognised for overriding on-disk config.
const DefaultAPIURL = "https://api.hostim.dev"
DefaultAPIURL is the production Hostim API base URL.
Variables ¶
var ErrNoProject = errors.New("no project selected: run `hostim use <project>` or pass -p/--project")
ErrNoProject is returned when a project-scoped command has no project set via flag, environment or config.
var ErrNoToken = errors.New("not logged in: run `hostim login` or set HOSTIM_TOKEN")
ErrNoToken is returned when no API token can be resolved.
Functions ¶
Types ¶
type File ¶
type File struct {
Token string `yaml:"token,omitempty"`
APIURL string `yaml:"apiUrl,omitempty"`
CurrentProject string `yaml:"currentProject,omitempty"`
}
File is the persisted configuration.
type Resolved ¶
type Resolved struct {
Token string
APIURL string
Project string
// TokenSource / ProjectSource describe where each value came from, for
// diagnostics (e.g. `hostim whoami`).
TokenSource string
ProjectSource string
}
Resolved is the effective configuration after applying precedence.
func Resolve ¶
Resolve applies precedence flag > env > file for each field. The API URL always falls back to DefaultAPIURL. Token and project may be empty; callers that require them should check and surface ErrNoToken / ErrNoProject.
func (Resolved) RequireProject ¶
RequireProject returns the resolved project or ErrNoProject.