config

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package config manages named contexts (kubectl-style) persisted to ~/.vibexp/config.yaml. It also resolves the effective runtime settings using the precedence: flag > env > active context.

Index

Constants

View Source
const (
	EnvContext = "VIBEXP_CONTEXT"
	EnvBaseURL = "VIBEXP_BASE_URL"
	EnvTeam    = "VIBEXP_TEAM"
	EnvProject = "VIBEXP_PROJECT"
	EnvFormat  = "VIBEXP_FORMAT"
)

Environment variable names honored during resolution.

Variables

This section is empty.

Functions

func DefaultPath

func DefaultPath() (string, error)

DefaultPath returns ~/.vibexp/config.yaml.

Types

type Context

type Context struct {
	Name           string `koanf:"name" yaml:"name"`
	BaseURL        string `koanf:"base_url" yaml:"base_url"`
	DefaultTeam    string `koanf:"team" yaml:"team,omitempty"`
	DefaultProject string `koanf:"project" yaml:"project,omitempty"`
}

Context is a single named target: a base URL plus optional default team and project. Credentials are NOT stored here — they live in credentials.json.

type File

type File struct {
	CurrentContext string    `koanf:"current_context" yaml:"current_context"`
	Contexts       []Context `koanf:"contexts" yaml:"contexts"`
}

File is the on-disk config document.

func (*File) Find

func (f *File) Find(name string) *Context

Find returns the context with the given name, or nil if absent.

func (*File) Resolve

func (f *File) Resolve(o Overrides, env Getenv) Runtime

Resolve computes the effective Runtime using precedence flag > env > active context, per field. The active context is chosen by the same precedence (flag --context > VIBEXP_CONTEXT > CurrentContext).

func (*File) Upsert

func (f *File) Upsert(c Context)

Upsert inserts or replaces a context by name.

type Getenv

type Getenv func(string) string

Getenv is the signature of an environment lookup (os.Getenv), injectable for tests.

type Overrides

type Overrides struct {
	Context string
	BaseURL string
	Team    string
	Project string
	Format  string
	Timeout time.Duration
}

Overrides carries values sourced from command-line flags. Empty strings mean "not set" and fall through to the next precedence level.

type Runtime

type Runtime struct {
	// ContextName is the name of the active context (may be empty if none).
	ContextName string
	BaseURL     string
	Team        string
	Project     string
	Timeout     time.Duration
	// Format is the resolved output format (flag > env; empty = auto). JQ and
	// IsTTY are populated by the CLI layer (flag-only / terminal detection).
	Format string
	JQ     string
	IsTTY  bool
	// Slugs looks up the UUID behind a team or project slug, which REST paths
	// require. The root installs it (api.NewSlugResolver) when it builds the
	// runtime, so api.Team/api.Project resolve lazily whatever order a command
	// builds its client and path in: only a command that is team- or
	// project-scoped pays for the lookup. When nil, a UUID still passes through
	// but a slug fails closed (exit 1).
	Slugs SlugResolver
}

Runtime is the fully-resolved effective configuration handed to commands.

type SlugResolver

type SlugResolver interface {
	TeamID(slug string) (string, error)
	ProjectID(teamID, slug string) (string, error)
}

SlugResolver maps a team or project slug to its UUID.

type Store

type Store struct {
	Path string
}

Store reads and writes the config file at Path.

func DefaultStore

func DefaultStore() (*Store, error)

DefaultStore returns a Store rooted at the default config path.

func (*Store) Load

func (s *Store) Load() (*File, error)

Load reads and parses the config file with koanf. A missing file yields an empty File (not an error) so a fresh install works out of the box.

func (*Store) Save

func (s *Store) Save(f *File) error

Save writes the config atomically (temp file + rename) with 0600 perms and a 0700 parent directory.

Jump to

Keyboard shortcuts

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