config

package
v0.1.0-dev.20260827000518 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package config provides unified configuration for star commands. Configuration is loaded from a hierarchy of config.yaml files:

  1. ${GIT_TOPLEVEL}/star/config.yaml (project - highest priority)
  2. ${XDG_CONFIG_HOME}/star/config.yaml (user defaults)
  3. Extension defaults (from extension.yaml files)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clean

func Clean() error

Clean removes generated config files.

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

func GolangciConfigPath(c *Config) string

GolangciConfigPath returns the path to use for golangci-lint config.

func LoadWithSources

func LoadWithSources() (*Config, []Source, error)

LoadWithSources loads configuration and returns the source of each file.

func MarkdownLintConfigPath

func MarkdownLintConfigPath(c *Config) string

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

func (a *Accessor) Bool(name string) 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

func (a *Accessor) BoolOr(name string, defaultVal bool) bool

BoolOr returns the bool value of the named field, or the default if not set.

func (*Accessor) Fields

func (a *Accessor) Fields() []string

Fields returns all field names in the struct.

func (*Accessor) Float

func (a *Accessor) Float(name string) float64

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) Get

func (a *Accessor) Get(name string) interface{}

Get returns the raw value of the named field as interface{}.

func (*Accessor) Has

func (a *Accessor) Has(name string) bool

Has returns true if the named field exists.

func (*Accessor) Int

func (a *Accessor) Int(name string) 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) IntOr

func (a *Accessor) IntOr(name string, defaultVal int) int

IntOr returns the int value of the named field, or the default if not set.

func (*Accessor) IsValid

func (a *Accessor) IsValid() bool

IsValid returns true if the accessor wraps a valid value.

func (*Accessor) Map

func (a *Accessor) Map(name string) map[string]interface{}

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) Raw

func (a *Accessor) Raw() reflect.Value

Raw returns the underlying reflect.Value.

func (*Accessor) String

func (a *Accessor) String(name string) 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

func (a *Accessor) StringOr(name, defaultVal string) string

StringOr returns the string value of the named field, or the default if not set.

func (*Accessor) StringSlice

func (a *Accessor) StringSlice(name string) []string

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

func (a *Accessor) StringSliceOr(name string, defaultVal []string) []string

StringSliceOr returns the []string value, or the default if not set.

func (*Accessor) Struct

func (a *Accessor) Struct(name string) *Accessor

Struct returns a Accessor for the named nested struct field. Returns an invalid accessor if the field doesn't exist or isn't a struct.

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

func Load() (*Config, error)

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) Accessor

func (c *Config) Accessor(path string) *Accessor

Accessor returns a typed accessor for a section at the given path.

func (*Config) GetSpec

func (c *Config) GetSpec(path string) (Spec, bool)

GetSpec returns the Spec for an extension path.

func (*Config) LoadFromFiles

func (c *Config) LoadFromFiles() error

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

func (c *Config) MergeYAML(data []byte) error

MergeYAML parses YAML bytes and merges values into the extension hierarchy.

func (*Config) Navigate

func (c *Config) Navigate(path string) interface{}

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

func (c *Config) RegisterExtension(path string, spec Spec) error

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

func (c *Config) ToStarlark() starlark.Value

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) Children

func (e *Element) Children() map[string]interface{}

Children returns all registered children.

func (*Element) Get

func (e *Element) Get(name string) interface{}

Get retrieves a child by name.

func (*Element) Navigate

func (e *Element) Navigate(path string) interface{}

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

func (*Element) Path

func (e *Element) Path() string

Path returns the dotted path of this element in the config hierarchy.

func (*Element) Register

func (e *Element) Register(name string, child interface{})

Register adds a child to this element. The child's path is computed relative to this element's path.

func (*Element) SetPath

func (e *Element) SetPath(path string)

SetPath sets the path of this element. Used during registration.

type Source

type Source struct {
	Path   string
	Exists bool
}

Source describes a configuration file location and whether it exists.

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) Attr

func (v *Value) Attr(name string) (starlark.Value, error)

Attr returns the value of the named attribute. Implements starlark.HasAttrs.

func (*Value) AttrNames

func (v *Value) AttrNames() []string

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.

func (*Value) Hash

func (v *Value) Hash() (uint32, error)

Hash returns a hash for the Value. Config values are not hashable.

func (*Value) String

func (v *Value) String() string

String returns a string representation of the Value.

func (*Value) Truth

func (v *Value) Truth() starlark.Bool

Truth returns the Starlark truth value. Value is always truthy.

func (*Value) Type

func (v *Value) Type() string

Type returns the Starlark type name.

Jump to

Keyboard shortcuts

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