config

package
v0.0.0-...-e6c4605 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package config provides configuration management for LeapSQL CLI.

This package provides CLI-specific configuration fields and functionality. Shared types (TargetConfig, LintConfig, DocsConfig, RuleOptions) are in pkg/core.

Index

Constants

View Source
const (
	DefaultStateFile = ".leapsql/state.db"
	DefaultEnv       = "dev"
	DefaultOutput    = "auto" // Auto-detect: TTY=text, non-TTY=markdown
)

CLI-specific default configuration values. Shared defaults (ModelsDir, SeedsDir, MacrosDir) come from internal/config.

Variables

This section is empty.

Functions

func DefaultSchemaForType

func DefaultSchemaForType(dbType string) string

DefaultSchemaForType returns the default schema for a database type. This is a convenience wrapper that delegates to the shared config function.

func GetConfigFileUsed

func GetConfigFileUsed() string

GetConfigFileUsed returns the path to the config file being used, if any.

func GetLogger

func GetLogger(ctx context.Context) *slog.Logger

GetLogger retrieves the logger from the command context.

func LoggerKey

func LoggerKey() interface{}

LoggerKey returns the context key used for storing the logger. This allows the commands package to retrieve the logger from context without creating an import cycle with the cli package.

func MergeTargetConfig

func MergeTargetConfig(base, override *core.TargetConfig) *core.TargetConfig

MergeTargetConfig merges two target configs, with override taking precedence.

func ResetConfig

func ResetConfig()

ResetConfig resets the koanf instance. Used for testing.

Types

type Config

type Config struct {
	ProjectRoot  string               `koanf:"-"` // Computed project root, not from config file
	ModelsDir    string               `koanf:"models_dir"`
	SeedsDir     string               `koanf:"seeds_dir"`
	MacrosDir    string               `koanf:"macros_dir"`
	DatabasePath string               `koanf:"database"` // Deprecated: use Target.Database
	StatePath    string               `koanf:"state_path"`
	Environment  string               `koanf:"environment"`
	Verbose      bool                 `koanf:"verbose"`
	OutputFormat string               `koanf:"output"`
	Target       *core.TargetConfig   `koanf:"target"`
	Lint         *core.LintConfig     `koanf:"lint"`
	UI           *UIConfig            `koanf:"ui"`
	Environments map[string]EnvConfig `koanf:"environments"`
}

Config holds all CLI configuration options.

func GetCurrentConfig

func GetCurrentConfig() *Config

GetCurrentConfig returns the currently loaded configuration. This is available after LoadConfig or LoadConfigWithTarget is called.

func LoadConfig

func LoadConfig(cfgFile string, flags *pflag.FlagSet) (*Config, error)

LoadConfig loads configuration from file, environment variables, and flags. Precedence (highest to lowest): flags > env vars > config file > defaults

func LoadConfigWithTarget

func LoadConfigWithTarget(cfgFile string, targetOverride string, flags *pflag.FlagSet) (*Config, error)

LoadConfigWithTarget loads configuration with an optional target override. The targetOverride parameter specifies which environment's target to use. The flags parameter allows CLI flags to override config file and env var values.

func (*Config) GetUIConfig

func (c *Config) GetUIConfig() *UIConfig

GetUIConfig returns the UI config with defaults applied for any unset values.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks if the configuration is valid.

func (*Config) ValidateDirectories

func (c *Config) ValidateDirectories() error

ValidateDirectories checks if required directories exist.

type EnvConfig

type EnvConfig struct {
	DatabasePath string             `koanf:"database"` // Deprecated: use Target.Database
	ModelsDir    string             `koanf:"models_dir"`
	SeedsDir     string             `koanf:"seeds_dir"`
	MacrosDir    string             `koanf:"macros_dir"`
	Target       *core.TargetConfig `koanf:"target"`
}

EnvConfig holds environment-specific configuration overrides.

type UIConfig

type UIConfig struct {
	Port             int    `koanf:"port"`
	AutoOpen         bool   `koanf:"auto_open"`
	Watch            bool   `koanf:"watch"`
	Theme            string `koanf:"theme"`
	DataPreviewLimit int    `koanf:"data_preview_limit"`
}

UIConfig holds configuration for the UI server.

func DefaultUIConfig

func DefaultUIConfig() *UIConfig

DefaultUIConfig returns a UIConfig with default values.

Jump to

Keyboard shortcuts

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