core

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2025 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConfigPathDefault = ".envctl.yaml"
	ConfigPathEnv     = "ENVCTL_CONFIG"
)

Variables

View Source
var (
	ErrCircularDependency = errors.New("circular dependency")
	ErrUnknownEnvironment = errors.New("unknown environment")
)
View Source
var ConfigContentDefault []byte

Functions

func ConfigPath

func ConfigPath(args []string) (string, error)

ConfigPath resolves and returns the config path. Lookup order:

  • Flag
  • Environment variable
  • Default path name

Types

type App

type App struct {
	Config *Config
	Logger *Logger
	Meta   *Meta
	IO     *ui.IOStreams
	UI     *ui.UserInterface

	Stores       *stores.StoreService
	Environments *EnvironmentService
	Exec         *exec.ExecService
	// contains filtered or unexported fields
}

App contains global and/or singleton application data.

func AppForContext

func AppForContext(ctx context.Context) *App

AppForContext returns the app singleton stored in the given context.

func NewApp

func NewApp(version, commit, date, path string) (*App, error)

NewApp returns the default App singleton. It will be minimally initialized with metadata and config. Call `Init()` after flag parsing to complete initialization.

func NewTestApp

func NewTestApp() *App

NewTestApp returns the test App singleton. All properties will be configured for testing (mocks, stubs, etc).

func (*App) Close

func (a *App) Close() error

Close ensures all app resources have been closed.

func (*App) Context

func (a *App) Context() context.Context

Context returns the root context.Context for the app.

func (*App) Init

func (a *App) Init() error

Init initializes and configures the app. It must be called once flags have been parsed.

func (*App) InitForTest

func (a *App) InitForTest()

Init initializes and configures the app for unit testing.

type Config

type Config struct {
	ConfigPath string
	Color      bool   `yaml:"color" env:"ENVCTL_COLOR" default:"true"`
	Debug      bool   `yaml:"debug" env:"ENVCTL_DEBUG"`
	Prompt     bool   `yaml:"prompt" env:"ENVCTL_PROMPT" default:"true"`
	LogLevel   string `yaml:"log_level" env:"ENVCTL_LOG_LEVEL" default:"warn" validate:"oneof=debug info warn error fatal"` //nolint: lll

	Version      string        `yaml:"version"`
	DotEnv       DotEnvConfig  `yaml:"dotenv"`
	Environments []Environment `yaml:"environments"`
}

func NewConfigFromPath

func NewConfigFromPath(path string) (*Config, error)

NewConfigFromPath returns a new config for the file at path.

func NewTestConfig

func NewTestConfig() (*Config, error)

NewTestConfig returns a new Config for unit tests populated with default values.

func (*Config) EnvironmentNames added in v0.3.0

func (c *Config) EnvironmentNames() []string

type DotEnvConfig added in v0.5.0

type DotEnvConfig struct {
	Enabled     bool               `yaml:"enabled" env:"ENVCTL_DOTENV_ENABLED"`
	BasePath    string             `yaml:"base_path" env:"ENVCTL_DOTENV_BASE_PATH"`
	QuoteStyle  dotenv.QuoteStyle  `yaml:"quote_style" env:"ENVCTL_DOTENV_QUOTE_STYLE" default:"double" validate:"oneof=none single double"` //nolint: lll
	EscapeStyle dotenv.EscapeStyle `yaml:"escape_style" env:"ENVCTL_DOTENV_ESCAPE_STYLE" default:"default" validate:"oneof=default compose"` //nolint: lll
}

type Environment added in v0.3.0

type Environment struct {
	Name    string      `yaml:"name"`
	Extends []string    `yaml:"extends"`
	Vars    models.Vars `yaml:"vars"`
}

type EnvironmentService added in v0.3.0

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

func NewEnvironmentService added in v0.3.0

func NewEnvironmentService(config *Config) *EnvironmentService

func (*EnvironmentService) Get added in v0.3.0

type Logger

type Logger struct {
	*log.Logger
}

Logger is a simple wrapper around the charmbracelet/log package.

func NewLogger

func NewLogger(ios *ui.IOStreams, config *Config) *Logger

NewLogger returns a new Logger.

type Meta

type Meta struct {
	BuildCommit    string
	BuildTime      time.Time
	BuildGoVersion string
	BuildVersion   string
	BuildChecksum  string
	Version        string
	GOOS           string
	GOARCH         string
}

Meta contains application metadata (version, os, build info, etc).

func NewMeta

func NewMeta(version, commit, date string) *Meta

NewMeta returns a new Meta struct.

Jump to

Keyboard shortcuts

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