types

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package types defines the core types and interfaces used throughout dodot. This includes interfaces for Trigger, PowerUp, and Action, as well as data structures like Pack, TriggerMatch, and Matcher.

Index

Constants

View Source
const (
	// ShellIntegrationSnippet is the line users need to add to their shell config
	ShellIntegrationSnippet = `[ -f "$HOME/.local/share/dodot/shell/dodot-init.sh" ] && source "$HOME/.local/share/dodot/shell/dodot-init.sh"`

	// ShellIntegrationSnippetWithCustomDir is the snippet template for custom DODOT_DATA_DIR
	ShellIntegrationSnippetWithCustomDir = `[ -f "%s/shell/dodot-init.sh" ] && source "%s/shell/dodot-init.sh"`

	// FishIntegrationSnippet is the line for Fish shell users
	FishIntegrationSnippet = `if test -f "$HOME/.local/share/dodot/shell/dodot-init.fish"
    source "$HOME/.local/share/dodot/shell/dodot-init.fish"
end`
)

Shell integration constants

View Source
const (
	// OverridePriority is a high priority value for config overrides
	OverridePriority = 100
)

Variables

This section is empty.

Functions

func GetShellIntegrationSnippet

func GetShellIntegrationSnippet(shell string, dataDir string) string

GetShellIntegrationSnippet returns the appropriate shell integration snippet If dataDir is provided, it uses that path; otherwise it uses the default snippet

Types

type Action

type Action struct {
	// Type specifies what kind of action this is
	Type ActionType

	// Description is a human-readable description of what this action does
	Description string

	// Source is the source path (for link, copy operations)
	Source string

	// Target is the target path (for link, copy, write operations)
	Target string

	// Content is the content to write (for write, append operations)
	Content string

	// Mode is the file permissions (for write, mkdir operations)
	Mode uint32

	// Command is the command to run (for run operations)
	Command string

	// Args are the arguments for the command (for run operations)
	Args []string

	// Pack is the name of the pack that generated this action
	Pack string

	// PowerUpName is the name of the power-up that generated this action
	PowerUpName string

	// Priority determines the order of execution (higher = executed first)
	Priority int

	// Metadata contains any additional data for this action
	Metadata map[string]interface{}
}

Action represents a high-level operation to be performed. Actions are generated by PowerUps and later converted to filesystem operations.

type ActionType

type ActionType string

ActionType represents the type of action to be performed

const (
	// ActionTypeLink creates a symbolic link
	ActionTypeLink ActionType = "link"

	// ActionTypeCopy copies a file
	ActionTypeCopy ActionType = "copy"

	// ActionTypeWrite writes content to a file
	ActionTypeWrite ActionType = "write"

	// ActionTypeAppend appends content to a file
	ActionTypeAppend ActionType = "append"

	// ActionTypeMkdir creates a directory
	ActionTypeMkdir ActionType = "mkdir"

	// ActionTypeShellSource adds a file to be sourced by the shell
	ActionTypeShellSource ActionType = "shell_source"

	// ActionTypePathAdd adds a directory to PATH
	ActionTypePathAdd ActionType = "path_add"

	// ActionTypeRun executes a command
	ActionTypeRun ActionType = "run"

	// ActionTypeBrew processes a Brewfile
	ActionTypeBrew ActionType = "brew"

	// ActionTypeInstall runs an install script
	ActionTypeInstall ActionType = "install"

	// ActionTypeTemplate processes a template file
	ActionTypeTemplate ActionType = "template"

	// ActionTypeRead reads file contents
	ActionTypeRead ActionType = "read"

	// ActionTypeChecksum calculates file checksum
	ActionTypeChecksum ActionType = "checksum"
)

type DisplayFile added in v0.1.3

type DisplayFile struct {
	PowerUp      string     `json:"powerUp"`
	Path         string     `json:"path"`
	Status       string     `json:"status"` // File-level: "success", "error", "queue", "config", "ignored"
	Message      string     `json:"message"`
	IsOverride   bool       `json:"isOverride"`   // File power-up was overridden in .dodot.toml
	LastExecuted *time.Time `json:"lastExecuted"` // When operation was last executed
}

DisplayFile represents a single file within a pack for display.

type DisplayPack added in v0.1.3

type DisplayPack struct {
	Name      string        `json:"name"`
	Status    string        `json:"status"` // Aggregated: "alert", "success", "queue"
	Files     []DisplayFile `json:"files"`
	HasConfig bool          `json:"hasConfig"` // Pack has .dodot.toml
	IsIgnored bool          `json:"isIgnored"` // Pack has .dodotignore
}

DisplayPack represents a single pack for display.

func (*DisplayPack) GetPackStatus added in v0.1.3

func (dp *DisplayPack) GetPackStatus() string

GetPackStatus determines the pack-level status based on its files. Following the aggregation rules from the design: - If ANY file has ERROR status → Pack status is "alert" - If ALL files have SUCCESS status → Pack status is "success" - Empty pack or mixed states → Pack status is "queue"

type DisplayResult added in v0.1.3

type DisplayResult struct {
	Command   string        `json:"command"` // "status", "deploy", "install"
	Packs     []DisplayPack `json:"packs"`
	DryRun    bool          `json:"dryRun"` // For deploy/install commands
	Timestamp time.Time     `json:"timestamp"`
}

DisplayResult is the top-level structure for commands that produce rich output. This replaces the old PackStatusResult and is used by status, deploy, and install commands.

type ExecutionContext added in v0.1.3

type ExecutionContext struct {
	// Command is the command being executed (deploy, install, etc.)
	Command string

	// PackResults contains results organized by pack
	PackResults map[string]*PackExecutionResult

	// StartTime is when execution began
	StartTime time.Time

	// EndTime is when execution completed
	EndTime time.Time

	// DryRun indicates if this was a dry run
	DryRun bool

	// TotalOperations is the total count of operations across all packs
	TotalOperations int

	// CompletedOperations is the count of successfully completed operations
	CompletedOperations int

	// FailedOperations is the count of failed operations
	FailedOperations int

	// SkippedOperations is the count of skipped operations
	SkippedOperations int
}

ExecutionContext tracks the complete context and results of a command execution

func NewExecutionContext added in v0.1.3

func NewExecutionContext(command string, dryRun bool) *ExecutionContext

NewExecutionContext creates a new execution context

func (*ExecutionContext) AddPackResult added in v0.1.3

func (ec *ExecutionContext) AddPackResult(packName string, result *PackExecutionResult)

AddPackResult adds or updates a pack result

func (*ExecutionContext) Complete added in v0.1.3

func (ec *ExecutionContext) Complete()

Complete marks the execution as complete

func (*ExecutionContext) GetPackResult added in v0.1.3

func (ec *ExecutionContext) GetPackResult(packName string) (*PackExecutionResult, bool)

GetPackResult retrieves a pack result by name

type ExecutionResult

type ExecutionResult struct {
	Packs      []string    `json:"packs"`      // Packs that were processed
	Operations []Operation `json:"operations"` // Operations planned (not yet executed)
	DryRun     bool        `json:"dryRun"`     // Whether this was a dry run
}

ExecutionResult holds the outcome of an 'install' or 'deploy' command. It details the operations that were/would be performed. IMPORTANT: This contains PLANNED operations, not executed ones. The operations must still be executed using an appropriate executor (e.g., CombinedExecutor for operations that include OperationExecute).

type ExecutionStatus added in v0.1.3

type ExecutionStatus string

ExecutionStatus represents the overall status of a pack's execution

const (
	// ExecutionStatusSuccess means all operations succeeded
	ExecutionStatusSuccess ExecutionStatus = "success"

	// ExecutionStatusPartial means some operations succeeded, some failed
	ExecutionStatusPartial ExecutionStatus = "partial"

	// ExecutionStatusError means all operations failed
	ExecutionStatusError ExecutionStatus = "error"

	// ExecutionStatusSkipped means all operations were skipped
	ExecutionStatusSkipped ExecutionStatus = "skipped"

	// ExecutionStatusPending means execution hasn't started
	ExecutionStatusPending ExecutionStatus = "pending"
)

type FileStatus added in v0.1.3

type FileStatus struct {
	// Path is the file or directory path
	Path string

	// PowerUp is the power-up that manages this file
	PowerUp string

	// Status is the current status of the file
	Status OperationStatus

	// Message provides additional context about the status
	Message string

	// LastApplied is when the file was last successfully applied
	LastApplied time.Time

	// Metadata contains power-up specific status information
	// For example:
	// - Symlinks: target path, whether link is valid
	// - Profiles: which shell files contain entries
	// - PATH: whether directory is in PATH
	// - Homebrew: package version, installation status
	Metadata map[string]interface{}
}

FileStatus represents the current status of a file managed by dodot

type FillResult

type FillResult struct {
	PackName     string      `json:"packName"`
	FilesCreated []string    `json:"filesCreated"`
	Operations   []Operation `json:"operations"`
}

FillResult holds the result of the 'fill' command.

type IgnoreRule

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

IgnoreRule defines a file or pattern to be ignored

type InitResult

type InitResult struct {
	PackName     string      `json:"packName"`
	Path         string      `json:"path"`
	FilesCreated []string    `json:"filesCreated"`
	Operations   []Operation `json:"operations"`
}

InitResult holds the result of the 'init' command.

type ListPacksResult

type ListPacksResult struct {
	Packs []PackInfo `json:"packs"`
}

ListPacksResult holds the result of the 'list' command.

type Matcher

type Matcher struct {
	// Name is an optional name for this matcher
	Name string

	// TriggerName specifies which trigger to use
	TriggerName string

	// PowerUpName specifies which power-up to invoke on match
	PowerUpName string

	// Priority determines the order of matcher evaluation (higher = first)
	Priority int

	// Options contains configuration for both trigger and power-up
	Options map[string]interface{}

	// TriggerOptions contains trigger-specific options
	TriggerOptions map[string]interface{}

	// PowerUpOptions contains power-up-specific options
	PowerUpOptions map[string]interface{}

	// Enabled indicates if this matcher is active
	Enabled bool
}

Matcher connects triggers to power-ups. It specifies: "when this trigger fires, invoke this power-up with these options."

type MatcherConfig

type MatcherConfig struct {
	// Name is an optional name for this matcher
	Name string `toml:"name"`

	// Trigger specifies which trigger to use
	Trigger string `toml:"trigger"`

	// PowerUp specifies which power-up to invoke
	PowerUp string `toml:"powerup"`

	// Priority for this matcher
	Priority int `toml:"priority"`

	// Pattern is a common trigger option (for convenience)
	Pattern string `toml:"pattern"`

	// Target is a common power-up option (for convenience)
	Target string `toml:"target"`

	// Options for trigger and power-up configuration
	Options map[string]interface{} `toml:"options"`

	// TriggerOptions for trigger-specific configuration
	TriggerOptions map[string]interface{} `toml:"trigger_options"`

	// PowerUpOptions for power-up-specific configuration
	PowerUpOptions map[string]interface{} `toml:"powerup_options"`

	// Enabled indicates if this matcher is active (default: true)
	Enabled *bool `toml:"enabled"`
}

MatcherConfig represents matcher configuration from TOML files

type Operation

type Operation struct {
	// Type is the type of operation
	Type OperationType

	// Source is the source path (for symlinks, copies)
	Source string

	// Target is the target path
	Target string

	// Content is the content to write (for write operations)
	Content string

	// Mode is the file permissions (optional)
	Mode *uint32

	// Description is a human-readable description
	Description string

	// Status is the current state of the operation
	Status OperationStatus

	// Command is the command to execute (for execute operations)
	Command string

	// Args are the arguments for the command (for execute operations)
	Args []string

	// WorkingDir is the working directory for execution (optional)
	WorkingDir string

	// EnvironmentVars are additional environment variables (optional)
	EnvironmentVars map[string]string

	// Pack is the name of the pack that originated this operation
	Pack string

	// PowerUp is the name of the PowerUp that generated this operation
	PowerUp string

	// TriggerInfo contains information about the original trigger match
	TriggerInfo *TriggerMatchInfo

	// Metadata preserves custom metadata from the Action
	Metadata map[string]interface{}

	// GroupID allows grouping related operations together
	GroupID string
}

Operation represents a low-level file system operation These are the actual operations that will be performed by synthfs

type OperationResult added in v0.1.3

type OperationResult struct {
	// Operation that was executed
	Operation *Operation

	// Status is the final status after execution
	Status OperationStatus

	// Error contains any error that occurred
	Error error

	// StartTime is when the operation began
	StartTime time.Time

	// EndTime is when the operation completed
	EndTime time.Time

	// Output contains any output from the operation (for execute operations)
	Output string

	// Metadata can contain additional execution information
	Metadata map[string]interface{}
}

OperationResult tracks the result of a single operation execution

type OperationStatus added in v0.1.1

type OperationStatus string

OperationStatus defines the state of an operation

const (
	// StatusReady means the operation is ready to be executed
	StatusReady OperationStatus = "ready"
	// StatusSkipped means the operation was skipped (e.g., idempotent action)
	StatusSkipped OperationStatus = "skipped"
	// StatusConflict means the operation cannot be performed due to a conflict
	StatusConflict OperationStatus = "conflict"
	// StatusError means the operation resulted in an error
	StatusError OperationStatus = "error"
	// StatusUnknown means the status could not be determined
	StatusUnknown OperationStatus = "unknown"
)

type OperationType

type OperationType string

OperationType defines the type of file system operation

const (
	// OperationCreateSymlink creates a symbolic link
	OperationCreateSymlink OperationType = "create_symlink"

	// OperationCreateDir creates a directory
	OperationCreateDir OperationType = "create_dir"

	// OperationCopyFile copies a file
	OperationCopyFile OperationType = "copy_file"

	// OperationWriteFile writes content to a file
	OperationWriteFile OperationType = "write_file"

	// OperationDeleteFile deletes a file
	OperationDeleteFile OperationType = "delete_file"

	// OperationBackupFile creates a backup of a file
	OperationBackupFile OperationType = "backup_file"

	// OperationReadFile reads file contents
	OperationReadFile OperationType = "read_file"

	// OperationChecksum calculates file checksum
	OperationChecksum OperationType = "checksum"

	// OperationExecute executes a command or script
	OperationExecute OperationType = "execute"
)

type OverrideRule

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

OverrideRule defines a behavior override for a specific file or pattern

type Pack

type Pack struct {
	// Name is the pack name (usually the directory name)
	Name string

	// Path is the absolute path to the pack directory
	Path string

	// Config contains pack-specific configuration from .dodot.toml
	Config PackConfig

	// Metadata contains any additional pack information
	Metadata map[string]interface{}
}

Pack represents a directory containing dotfiles and configuration

type PackConfig

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

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

func (*PackConfig) FindOverride

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

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 PackExecutionResult added in v0.1.3

type PackExecutionResult struct {
	// Pack is the pack being executed
	Pack *Pack

	// Operations contains all operations and their results
	Operations []*OperationResult

	// Status is the aggregated status for this pack
	Status ExecutionStatus

	// StartTime is when this pack's execution began
	StartTime time.Time

	// EndTime is when this pack's execution completed
	EndTime time.Time

	// TotalOperations in this pack
	TotalOperations int

	// CompletedOperations in this pack
	CompletedOperations int

	// FailedOperations in this pack
	FailedOperations int

	// SkippedOperations in this pack
	SkippedOperations int
}

PackExecutionResult contains the execution results for a single pack

func NewPackExecutionResult added in v0.1.3

func NewPackExecutionResult(pack *Pack) *PackExecutionResult

NewPackExecutionResult creates a new pack execution result

func (*PackExecutionResult) AddOperationResult added in v0.1.3

func (per *PackExecutionResult) AddOperationResult(result *OperationResult)

AddOperationResult adds an operation result and updates statistics

func (*PackExecutionResult) Complete added in v0.1.3

func (per *PackExecutionResult) Complete()

Complete marks the pack execution as complete

func (*PackExecutionResult) GroupOperationsByGroupID added in v0.1.3

func (per *PackExecutionResult) GroupOperationsByGroupID() map[string][]*OperationResult

GroupOperationsByGroupID groups operations by their GroupID

func (*PackExecutionResult) GroupOperationsByPowerUp added in v0.1.3

func (per *PackExecutionResult) GroupOperationsByPowerUp() map[string][]*OperationResult

GroupOperationsByPowerUp groups operations by their PowerUp for display

type PackInfo

type PackInfo struct {
	Name string `json:"name"`
	Path string `json:"path"`
}

PackInfo contains summary information about a single pack.

type PowerUp

type PowerUp interface {
	// Name returns the unique name of this power-up
	Name() string

	// Description returns a human-readable description of what this power-up does
	Description() string

	// RunMode returns whether this power-up runs once or many times
	RunMode() RunMode

	// Process takes a group of trigger matches and generates actions
	// The matches are grouped by pack and options before being passed here
	Process(matches []TriggerMatch) ([]Action, error)

	// ValidateOptions checks if the provided options are valid for this power-up
	ValidateOptions(options map[string]interface{}) error

	// GetTemplateContent returns the template content for this power-up
	// Returns empty string if the power-up doesn't provide a template
	GetTemplateContent() string
}

PowerUp is an interface for action generators that process matched files. PowerUps receive groups of files that their associated triggers matched, and generate high-level actions describing what should be done.

type PowerUpFactory

type PowerUpFactory func(options map[string]interface{}) (PowerUp, error)

PowerUpFactory is a function that creates a new PowerUp instance It takes a map of options to configure the power-up

type RunMode

type RunMode string

RunMode indicates how often a power-up should be executed

const (
	// RunModeMany indicates the power-up can be run multiple times safely
	RunModeMany RunMode = "many"

	// RunModeOnce indicates the power-up should only run once per pack
	RunModeOnce RunMode = "once"
)

type Trigger

type Trigger interface {
	// Name returns the unique name of this trigger
	Name() string

	// Description returns a human-readable description of what this trigger matches
	Description() string

	// Match checks if the given file or directory matches this trigger's pattern
	// It returns true if the file matches, along with any extracted metadata
	Match(path string, info fs.FileInfo) (bool, map[string]interface{})

	// Priority returns the priority of this trigger (higher = evaluated first)
	Priority() int

	// Type returns whether this is a specific or catchall trigger
	Type() TriggerType
}

Trigger is an interface for pattern-matching engines that scan files and directories within packs. When a trigger finds a match, it returns metadata about what was found.

type TriggerFactory

type TriggerFactory func(options map[string]interface{}) (Trigger, error)

TriggerFactory creates a new Trigger instance with the given options

type TriggerMatch

type TriggerMatch struct {
	// TriggerName is the name of the trigger that matched
	TriggerName string

	// Pack is the name of the pack containing the matched file
	Pack string

	// Path is the relative path within the pack
	Path string

	// AbsolutePath is the absolute path to the file
	AbsolutePath string

	// Metadata contains any additional data extracted by the trigger
	Metadata map[string]interface{}

	// PowerUpName is the name of the power-up that should process this match
	PowerUpName string

	// PowerUpOptions contains options to pass to the power-up
	PowerUpOptions map[string]interface{}

	// Priority determines the order of processing (higher = processed first)
	Priority int
}

TriggerMatch represents a successful trigger match on a file or directory

type TriggerMatchInfo added in v0.1.3

type TriggerMatchInfo struct {
	// TriggerName is the name of the trigger that matched
	TriggerName string

	// OriginalPath is the relative path within the pack that was matched
	OriginalPath string

	// Priority from the original trigger match
	Priority int
}

TriggerMatchInfo contains essential information from the original trigger match This is a lightweight version of TriggerMatch for preservation in Operations

type TriggerType added in v0.1.1

type TriggerType int

TriggerType represents the type of trigger - specific or catchall

const (
	// TriggerTypeSpecific is for triggers that match specific patterns
	TriggerTypeSpecific TriggerType = iota
	// TriggerTypeCatchall is for triggers that match everything not already matched
	TriggerTypeCatchall
)

Jump to

Keyboard shortcuts

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