Documentation
¶
Overview ¶
Package config provides unified configuration for star commands. Configuration is loaded from a hierarchy of config.yaml files:
- ${GIT_TOPLEVEL}/star/config.yaml (project - highest priority)
- ${XDG_CONFIG_HOME}/star/config.yaml (user defaults)
- Extension defaults (from extension.yaml files)
Index ¶
- func Clean() error
- func ClearTypeCache()
- func EnsureGitignore() error
- func GitWorkspaceRoot() string
- func GolangciConfigPath(c *Config) string
- func LoadWithSources() (*Config, []Source, error)
- func MarkdownLintConfigPath(c *Config) string
- func ResetGitWorkspaceRoot()
- func SetGitWorkspaceRoot(path string)
- type Accessor
- func (a *Accessor) Bool(name string) bool
- func (a *Accessor) BoolOr(name string, defaultVal bool) bool
- func (a *Accessor) Fields() []string
- func (a *Accessor) Float(name string) float64
- func (a *Accessor) Get(name string) interface{}
- func (a *Accessor) Has(name string) bool
- func (a *Accessor) Int(name string) int
- func (a *Accessor) IntOr(name string, defaultVal int) int
- func (a *Accessor) IsValid() bool
- func (a *Accessor) Map(name string) map[string]interface{}
- func (a *Accessor) Raw() reflect.Value
- func (a *Accessor) String(name string) string
- func (a *Accessor) StringOr(name, defaultVal string) string
- func (a *Accessor) StringSlice(name string) []string
- func (a *Accessor) StringSliceOr(name string, defaultVal []string) []string
- func (a *Accessor) Struct(name string) *Accessor
- type Config
- func (c *Config) Accessor(path string) *Accessor
- func (c *Config) GetSpec(path string) (Spec, bool)
- func (c *Config) LoadFromFiles() error
- func (c *Config) MergeYAML(data []byte) error
- func (c *Config) Navigate(path string) interface{}
- func (c *Config) RegisterExtension(path string, spec Spec) error
- func (c *Config) Sync() (*SyncResult, error)
- func (c *Config) ToStarlark() starlark.Value
- type Element
- type Source
- type Spec
- type SyncResult
- type Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClearTypeCache ¶
func ClearTypeCache()
ClearTypeCache clears the type cache. Useful for testing.
func EnsureGitignore ¶
func EnsureGitignore() error
EnsureGitignore ensures generated files are in .gitignore.
func GitWorkspaceRoot ¶
func GitWorkspaceRoot() string
GitWorkspaceRoot returns the cached git repository root. Returns empty string if not in a git repo.
func GolangciConfigPath ¶
GolangciConfigPath returns the path to use for golangci-lint config.
func LoadWithSources ¶
LoadWithSources loads configuration and returns the source of each file.
func MarkdownLintConfigPath ¶
MarkdownLintConfigPath returns the path to use for markdownlint config.
func ResetGitWorkspaceRoot ¶
func ResetGitWorkspaceRoot()
ResetGitWorkspaceRoot resets the git workspace root cache. The next call to GitWorkspaceRoot will re-detect from git.
func SetGitWorkspaceRoot ¶
func SetGitWorkspaceRoot(path string)
SetGitWorkspaceRoot sets the git workspace root for testing. Do ResetGitWorkspaceRoot to restore normal behavior.
Types ¶
type Accessor ¶
type Accessor struct {
// contains filtered or unexported fields
}
Accessor provides typed access to config struct fields via reflection. It wraps a reflect.Value and provides type-safe accessor methods.
func NewAccessor ¶
func NewAccessor(v interface{}) *Accessor
NewAccessor creates a Accessor for the given value. The value should be a struct or pointer to struct.
func (*Accessor) Bool ¶
Bool returns the bool value of the named field. Returns false if the field doesn't exist or isn't a bool.
func (*Accessor) BoolOr ¶
BoolOr returns the bool value of the named field, or the default if not set.
func (*Accessor) Float ¶
Float returns the float64 value of the named field. Returns 0 if the field doesn't exist or isn't a float type.
func (*Accessor) Int ¶
Int returns the int value of the named field. Returns 0 if the field doesn't exist or isn't an integer type.
func (*Accessor) Map ¶
Map returns the map[string]interface{} value of the named field. Returns nil if the field doesn't exist or isn't a map.
func (*Accessor) String ¶
String returns the string value of the named field. Returns empty string if the field doesn't exist or isn't a string.
func (*Accessor) StringOr ¶
StringOr returns the string value of the named field, or the default if not set.
func (*Accessor) StringSlice ¶
StringSlice returns the []string value of the named field. Returns nil if the field doesn't exist or isn't a string slice.
func (*Accessor) StringSliceOr ¶
StringSliceOr returns the []string value, or the default if not set.
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config provides a unified view of all configuration. Extensions register their config specs, then LoadFromFiles() merges values from star/config.yaml files into the registered hierarchy.
func Load ¶
Load creates a Config, registers no extensions, and loads from files. This is a convenience wrapper for tests and standalone use.
func New ¶
func New() *Config
New creates a Config with an empty extension hierarchy. Do RegisterExtension() to add config specs, then LoadFromFiles() to populate.
func (*Config) LoadFromFiles ¶
LoadFromFiles reads user and project star/config.yaml files and merges values into the registered extension hierarchy. Extensions must be registered before calling this.
func (*Config) MergeYAML ¶
MergeYAML parses YAML bytes and merges values into the extension hierarchy.
func (*Config) Navigate ¶
Navigate traverses the config hierarchy by dotted path. Returns the element or field value at the given path, or nil if not found.
func (*Config) RegisterExtension ¶
RegisterExtension registers an extension's config at a dotted path. Creates intermediate elements as needed.
func (*Config) Sync ¶
func (c *Config) Sync() (*SyncResult, error)
Sync generates tool-specific config files from star/config.yaml.
func (*Config) ToStarlark ¶
ToStarlark returns the config wrapped for Starlark access.
type Element ¶
type Element struct {
// contains filtered or unexported fields
}
Element is the base type embedded by all config sections. It supports hierarchical composition via Register and navigation via Navigate.
func (*Element) Navigate ¶
Navigate traverses the config hierarchy by dotted path. Returns the element or field value at the given path, or nil if not found.
Examples:
Navigate("") returns the element itself
Navigate("lint") returns the lint child element
Navigate("lint.copyright") returns the copyright child of lint
Navigate("lint.copyright.enabled") returns the enabled field value
type Spec ¶
type Spec struct {
Type string // Go type name (informational)
Fields map[string]string // field name → type (bool, string, int, []string, map[K]V)
Nested map[string]Spec // nested type definitions (e.g., Pattern)
Defaults map[string]interface{} // default values
}
Spec describes the configuration schema for an extension. It is used by Worker 3 (extension package) to register extension configs.
type SyncResult ¶
type SyncResult struct {
GolangciLint string // Path to generated .golangci.yaml
MarkdownLint string // Path to generated .markdownlint-cli2.yaml
PrecommitConfig string // Path to generated .pre-commit-config.yaml
FilesGenerated int
}
SyncResult describes what was synced.
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
Value wraps a Go struct for Starlark attribute access. It implements starlark.Value and starlark.HasAttrs.
func WrapAsStarlarkValue ¶
func WrapAsStarlarkValue(v interface{}) *Value
WrapAsStarlarkValue wraps any Go value for Starlark access. Returns a Value that provides attribute access via reflection.
func (*Value) AttrNames ¶
AttrNames returns the names of all available attributes. Implements starlark.HasAttrs.
func (*Value) Freeze ¶
func (v *Value) Freeze()
Freeze makes the Value immutable. This is a no-op since Go structs don't have a concept of mutability that matches Starlark's.