config

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2025 License: MIT Imports: 14 Imported by: 0

README

# dodot Configuration Package

This package centralizes all configuration for the dodot application.

## Phase 1 - Centralization (Completed)

In Phase 1, we've centralized the following configurations:

### 1. Handler Configuration
- **HandlerTemplates**: Templates for shell aliases and Brewfile
- **HandlerDefaults**: Default values like path handler target directory

### 2. Security Configuration
- Protected paths that should not be symlinked
- Home symlink permissions
- Backup and rollback settings
- Cleanup settings for dangling links

### 3. Pattern Configuration
- Pack ignore patterns
- Catchall exclusions
- Special file names

### 4. Priority Configuration
- Trigger priorities
- Handler priorities  
- Matcher priorities

### 5. File Permissions
- Directory permissions (0755)
- File permissions (0644)
- Executable permissions (0755)

### 6. Shell Integration
- Bash/Zsh snippets
- Fish snippets
- Custom directory support

### 7. Path Configuration
- Reserved for future user-configurable paths
- Internal datastore paths remain in pkg/paths/paths.go (not user-configurable)

### 8. Default Matchers
- Pre-configured matchers for common dotfile patterns

### 9. Pack Configuration (PackConfig)
- Pack-specific configuration from .dodot.toml files
- Ignore rules, override rules, and path mappings
- Moved from pkg/types to pkg/config to break import cycles

## Access Functions

All configuration is accessed through the functions in `access.go`:
- `Get()` - Returns the full configuration
- `GetHandlerTemplates()` - Returns handler templates
- `GetHandlerDefaults()` - Returns handler defaults
- `GetSecurity()` - Returns security settings
- etc.

## Known Issues and TODOs

### Hardcoded Values
- File permissions are still hardcoded throughout the codebase (executor, datastore, etc.)
- These should be updated to use centralized values in a future refactor

## Next Phases

### Phase 2 - Externalization
- Create YAML schema for all configuration
- Embed default configuration YAML in binary
- Parse and use YAML configuration at runtime

### Phase 3 - User Customization  
- Integrate koanf for configuration management
- Support user configuration files in dotfiles root
- Implement smart merging of user config over defaults

Documentation

Overview

Package config handles configuration management for dodot. It supports loading configuration from multiple sources including TOML files, environment variables, and command-line flags.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FileExists

func FileExists(path string) bool

FileExists is a helper to check if a file exists

func GenerateConfigContent added in v0.3.0

func GenerateConfigContent() string

GenerateConfigContent generates the configuration file content with commented values

func GetUserDefaultsContent added in v0.3.0

func GetUserDefaultsContent() string

GetUserDefaultsContent returns the content of the user defaults configuration file

func Initialize added in v0.3.0

func Initialize(cfg *Config)

Initialize sets up the global configuration

Types

type Config added in v0.1.1

type Config struct {
	Security         Security         `koanf:"security"`
	Patterns         Patterns         `koanf:"patterns"`
	Rules            []Rule           `koanf:"rules"`
	FilePermissions  FilePermissions  `koanf:"file_permissions"`
	ShellIntegration ShellIntegration `koanf:"shell_integration"`
	Paths            Paths            `koanf:"paths"`
	LinkPaths        LinkPaths        `koanf:"link_paths"`
	Mappings         Mappings         `koanf:"mappings"`
}

Config is the main configuration structure

func Default added in v0.1.1

func Default() *Config

Default returns the default configuration

func Get added in v0.3.0

func Get() *Config

Get returns the current configuration

func LoadConfiguration added in v0.3.0

func LoadConfiguration() (*Config, error)

func LoadPackConfiguration added in v0.3.0

func LoadPackConfiguration(baseConfig *Config, packPath string) (*Config, error)

LoadPackConfiguration loads a pack-specific config and merges it with the base config

func (*Config) GenerateRulesFromMapping added in v0.3.0

func (c *Config) GenerateRulesFromMapping() []Rule

GenerateRulesFromMapping creates rules based on mappings configuration

type FilePermissions added in v0.1.1

type FilePermissions struct {
	Directory  os.FileMode `koanf:"directory"`
	File       os.FileMode `koanf:"file"`
	Executable os.FileMode `koanf:"executable"`
}

FilePermissions holds file and directory permission settings IMPORTANT: These permissions are intentionally NOT used throughout the codebase. File permissions (0755, 0644, etc.) should remain hardcoded where they are used as they are security-critical and context-specific. This struct exists only for potential future use cases where centralized permissions might be beneficial.

func GetFilePermissions added in v0.3.0

func GetFilePermissions() FilePermissions

GetFilePermissions returns file permission configuration

type IgnoreRule added in v0.3.0

type IgnoreRule struct {
	Path string `toml:"path"`
}

IgnoreRule defines a file or pattern to be ignored

type LinkPaths added in v0.3.0

type LinkPaths struct {
	// CoreUnixExceptions lists tools that should always deploy to $HOME
	// These are typically security-critical or shell-expected locations
	// Release C: Layer 2 - Exception List
	CoreUnixExceptions map[string]bool `koanf:"force_home"`
}

LinkPaths holds link path mapping configuration

func GetLinkPaths added in v0.3.0

func GetLinkPaths() LinkPaths

GetLinkPaths returns link path configuration

type Mappings added in v0.3.0

type Mappings struct {
	// Path specifies directory names that should be added to PATH
	Path string `koanf:"path"`
	// Install specifies the filename pattern for install scripts
	Install string `koanf:"install"`
	// Shell specifies filename patterns for shell scripts
	Shell []string `koanf:"shell"`
	// Homebrew specifies the filename pattern for Homebrew files
	Homebrew string `koanf:"homebrew"`
}

Mappings holds file name to handler mappings

type OverrideRule added in v0.3.0

type OverrideRule struct {
	Path    string                 `toml:"path"`
	Handler string                 `toml:"handler"`
	With    map[string]interface{} `toml:"with"`
}

OverrideRule defines a behavior override for a specific file or pattern

type PackConfig added in v0.3.0

type PackConfig struct {
	Ignore   []IgnoreRule      `toml:"ignore"`
	Override []OverrideRule    `toml:"override"`
	Mappings map[string]string `toml:"mappings"`
}

PackConfig represents configuration options for a pack from .dodot.toml

func LoadPackConfig

func LoadPackConfig(configPath string) (PackConfig, error)

LoadPackConfig reads and parses a pack's .dodot.toml configuration file

func (*PackConfig) FindOverride added in v0.3.0

func (c *PackConfig) FindOverride(filename string) *OverrideRule

FindOverride returns the override rule that matches the given filename, if any. It prioritizes exact matches over pattern matches.

func (*PackConfig) IsIgnored added in v0.3.0

func (c *PackConfig) IsIgnored(filename string) bool

IsIgnored checks if a given file path should be ignored based on the pack's configuration. It matches the filename against the list of ignore rules.

type Paths added in v0.1.1

type Paths struct {
}

Paths holds path-related configuration NOTE: Internal datastore paths (StateDir, BackupsDir, etc.) are defined in pkg/paths/paths.go and are NOT user-configurable. They are part of dodot's internal structure and should remain consistent across all installations. This struct intentionally left empty for now but may hold user-configurable paths in the future.

func GetPaths added in v0.3.0

func GetPaths() Paths

GetPaths returns path configuration

type Patterns added in v0.1.1

type Patterns struct {
	PackIgnore      []string     `koanf:"pack_ignore" yaml:"packIgnore" json:"packIgnore"`
	CatchallExclude []string     `koanf:"catchall_exclude" yaml:"catchallExclude" json:"catchallExclude"`
	SpecialFiles    SpecialFiles `koanf:"special_files" yaml:"specialFiles" json:"specialFiles"`
}

Patterns holds various ignore and exclude patterns

func GetPatterns added in v0.3.0

func GetPatterns() Patterns

GetPatterns returns pattern configuration

type Rule added in v0.3.0

type Rule struct {
	Pattern string                 `koanf:"pattern" yaml:"pattern" json:"pattern"`
	Handler string                 `koanf:"handler" yaml:"handler" json:"handler"`
	Options map[string]interface{} `koanf:"options" yaml:"options" json:"options"`
}

Rule defines a pattern-to-handler mapping

func GetRules added in v0.3.0

func GetRules() []Rule

GetRules returns rule configuration

type Security added in v0.1.1

type Security struct {
	// ProtectedPaths defines paths that should not be symlinked for security reasons
	// TODO: Implement in pkg/handlers/lib/symlink/symlink.go ProcessLinking()
	ProtectedPaths map[string]bool `koanf:"protected_paths"`
}

Security holds security-related configuration

func GetSecurity added in v0.3.0

func GetSecurity() Security

GetSecurity returns security configuration

type ShellIntegration added in v0.1.1

type ShellIntegration struct {
	BashZshSnippet           string `koanf:"bash_zsh_snippet"`
	BashZshSnippetWithCustom string `koanf:"bash_zsh_snippet_with_custom"`
	FishSnippet              string `koanf:"fish_snippet"`
}

ShellIntegration holds shell integration snippets

func GetShellIntegration added in v0.3.0

func GetShellIntegration() ShellIntegration

GetShellIntegration returns shell integration configuration

type SpecialFiles added in v0.1.1

type SpecialFiles struct {
	PackConfig string `koanf:"pack_config"`
	IgnoreFile string `koanf:"ignore_file"`
}

SpecialFiles holds names of special configuration files

Jump to

Keyboard shortcuts

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