config

package
v0.2.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package config provides CLI-specific configuration management.

This package wraps the stackeye-go-sdk/config package to add CLI-specific functionality such as environment variable overrides and authentication validation helpers. The SDK package handles persistence and context management; this package adds runtime configuration concerns.

Environment variables (override config file values):

STACKEYE_API_KEY    - API key for authentication
STACKEYE_API_URL    - API server URL
STACKEYE_CONFIG     - Path to config file
STACKEYE_CONTEXT    - Context name to use

Usage:

cfg, err := config.Load()
if err != nil {
    return err
}

// Get API key with env override
apiKey := config.GetAPIKey(cfg)

// Require valid authentication
if err := config.RequireAuth(cfg); err != nil {
    return err
}

Index

Constants

View Source
const (
	// EnvAPIKey overrides the API key from config.
	EnvAPIKey = "STACKEYE_API_KEY"

	// EnvAPIURL overrides the API URL from config.
	EnvAPIURL = "STACKEYE_API_URL"

	// EnvConfig specifies a custom config file path.
	EnvConfig = "STACKEYE_CONFIG"

	// EnvContext overrides the current context.
	EnvContext = "STACKEYE_CONTEXT"
)

Environment variable names for configuration overrides.

View Source
const (
	// Output formats
	OutputFormatTable = sdkconfig.OutputFormatTable
	OutputFormatJSON  = sdkconfig.OutputFormatJSON
	OutputFormatYAML  = sdkconfig.OutputFormatYAML
	OutputFormatWide  = sdkconfig.OutputFormatWide

	// Color modes
	ColorModeAuto   = sdkconfig.ColorModeAuto
	ColorModeAlways = sdkconfig.ColorModeAlways
	ColorModeNever  = sdkconfig.ColorModeNever

	// Default values
	DefaultAPIURL = sdkconfig.DefaultAPIURL
)

Re-export SDK constants.

Variables

View Source
var (
	ErrNoCurrentContext = sdkconfig.ErrNoCurrentContext
	ErrContextNotFound  = sdkconfig.ErrContextNotFound
	ErrContextExists    = sdkconfig.ErrContextExists
)

Re-export SDK errors.

View Source
var (
	// ErrNotAuthenticated is returned when authentication is required but not configured.
	ErrNotAuthenticated = errors.New("not authenticated: run 'stackeye login' to authenticate")

	// ErrInvalidAPIKey is returned when the API key format is invalid.
	ErrInvalidAPIKey = errors.New("invalid API key format")
)

CLI-specific errors.

Functions

func ConfigDir

func ConfigDir() string

ConfigDir returns the path to the configuration directory.

func ConfigPath

func ConfigPath() string

ConfigPath returns the path to the configuration file. If STACKEYE_CONFIG is set, returns that path; otherwise returns default.

func EnsureConfigDir

func EnsureConfigDir() (string, error)

EnsureConfigDir creates the configuration directory if it doesn't exist. Returns the path to the config directory.

func GetAPIKey

func GetAPIKey(cfg *Config) string

GetAPIKey returns the effective API key, checking environment first. Returns empty string if no API key is configured.

func GetAPIURL

func GetAPIURL(cfg *Config) string

GetAPIURL returns the effective API URL, checking environment first. Returns DefaultAPIURL if no URL is configured.

func IsAuthenticated

func IsAuthenticated(cfg *Config) bool

IsAuthenticated returns true if valid authentication is configured. Checks both environment variables and config file.

func RequireAuth

func RequireAuth(cfg *Config) error

RequireAuth returns an error if no valid authentication is configured. Use this at the start of commands that require authentication.

func Save

func Save() error

Save saves configuration using the default manager.

func ValidateContextName

func ValidateContextName(name string) error

ValidateContextName checks if a context name is valid.

Types

type ColorMode

type ColorMode = sdkconfig.ColorMode

ColorMode specifies when to use colored output.

type Config

type Config = sdkconfig.Config

Config is the root configuration structure.

func Load

func Load() (*Config, error)

Load loads configuration using the default manager. This is a convenience function for simple use cases.

func NewConfig

func NewConfig() *Config

NewConfig creates a new empty configuration.

type Context

type Context = sdkconfig.Context

Context represents a named configuration context.

func NewContext

func NewContext() *Context

NewContext creates a new context with default values.

type ContextInfo

type ContextInfo = sdkconfig.ContextInfo

ContextInfo provides display information about a context.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager provides thread-safe access to configuration. Use GetManager() to obtain the singleton instance.

func GetManager

func GetManager() *Manager

GetManager returns the singleton configuration manager.

func (*Manager) Get

func (m *Manager) Get() *Config

Get returns the loaded configuration. Returns nil if Load() hasn't been called.

func (*Manager) Load

func (m *Manager) Load() (*Config, error)

Load loads the configuration, applying environment variable overrides. If STACKEYE_CONFIG is set, loads from that path; otherwise uses default location.

func (*Manager) Reload

func (m *Manager) Reload() (*Config, error)

Reload forces a reload of the configuration from disk.

func (*Manager) Save

func (m *Manager) Save() error

Save persists the current configuration to disk.

type OutputFormat

type OutputFormat = sdkconfig.OutputFormat

OutputFormat specifies the output format for commands.

type Preferences

type Preferences = sdkconfig.Preferences

Preferences holds user preferences for CLI behavior.

func NewPreferences

func NewPreferences() *Preferences

NewPreferences creates new preferences with default values.

Jump to

Keyboard shortcuts

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