config

package
v0.1.22 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: MIT Imports: 5 Imported by: 0

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

View Source
const (
	EnvToken   = "HOSTIM_TOKEN"
	EnvAPIURL  = "HOSTIM_API_URL"
	EnvProject = "HOSTIM_PROJECT"
)

Env var names recognised for overriding on-disk config.

View Source
const DefaultAPIURL = "https://api.hostim.dev"

DefaultAPIURL is the production Hostim API base URL.

Variables

View Source
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.

View Source
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

func Path

func Path() (string, error)

Path returns the config file path, honouring XDG_CONFIG_HOME.

func Save

func Save(f *File) error

Save writes the config file with 0600 permissions, creating parent dirs.

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.

func Load

func Load() (*File, error)

Load reads the config file. A missing file yields an empty File, not an error.

type Overrides

type Overrides struct {
	Token   string
	APIURL  string
	Project string
}

Overrides holds command-line flag values (empty string means unset).

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

func Resolve(f *File, o Overrides) Resolved

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

func (r Resolved) RequireProject() (string, error)

RequireProject returns the resolved project or ErrNoProject.

Jump to

Keyboard shortcuts

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