module

package
v0.0.0-...-29c325b Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LogValidateResult

func LogValidateResult(result *ValidateResult)

LogValidateResult logs the validation results in a structured format

Types

type FileMapping

type FileMapping struct {
	// contains filtered or unexported fields
}

FileMapping represents a two-way mapping between source and target files

func BuildFileMapping

func BuildFileMapping(modules []config.ModuleConfig) (*FileMapping, error)

BuildFileMapping creates a FileMapping from all modules in the config

func NewFileMapping

func NewFileMapping() *FileMapping

NewFileMapping creates a new empty FileMapping

func (*FileMapping) AddMapping

func (fm *FileMapping) AddMapping(source, target string)

AddMapping adds a source-target mapping to the FileMapping

func (*FileMapping) AddTemplateMapping

func (fm *FileMapping) AddTemplateMapping(source, target string)

AddTemplateMapping adds a template source-target mapping to the FileMapping

func (*FileMapping) GetAllMappings

func (fm *FileMapping) GetAllMappings() map[string]string

GetAllMappings returns all source-target mappings

func (*FileMapping) GetSource

func (fm *FileMapping) GetSource(target string) (string, bool)

GetSource returns the source path for a given target path

func (*FileMapping) GetTarget

func (fm *FileMapping) GetTarget(source string) (string, bool)

GetTarget returns the target path for a given source path

func (*FileMapping) GetTargetConflicts

func (fm *FileMapping) GetTargetConflicts() map[string][]string

GetTargetConflicts returns any duplicate target mappings

func (*FileMapping) GetTemplateMappings

func (fm *FileMapping) GetTemplateMappings() map[string]string

GetTemplateMappings returns all template source-target mappings

func (*FileMapping) IsTemplate

func (fm *FileMapping) IsTemplate(source string) bool

IsTemplate checks if a source file is a template

type FileOperation

type FileOperation struct {
	Type        OperationType
	Source      string
	Target      string
	Description string
}

FileOperation represents a file operation that would be performed

type GeneratedFileValidationResult

type GeneratedFileValidationResult struct {
	IsValid        bool
	Reason         string
	BackupRequired bool
}

GeneratedFileValidationResult contains the result of generated file validation

type InstallConfig

type InstallConfig struct {
	Mkdir     bool              `json:"mkdir"`
	Force     bool              `json:"force"`
	DryRun    bool              `json:"dry_run"`
	Vars      map[string]string `json:"vars,omitempty"`
	StatePath string            `json:"state_path"`
}

InstallConfig contains configuration for install operations

type InstallRequest

type InstallRequest struct {
	Modules     []config.ModuleConfig
	RootVars    map[string]string
	Mkdir       bool
	Force       bool
	DotfilesDir string
}

InstallRequest contains the parameters for an installation request

type InstallResult

type InstallResult struct {
	IsSuccess        bool
	Summary          string
	Errors           []string
	CreatedLinks     []FileOperation
	CreatedTemplates []FileOperation
	SkippedLinks     []FileOperation
}

InstallResult contains the results of an installation

func Install

func Install(modules []config.ModuleConfig, rootVars map[string]string, mkdir bool, force bool, dotfilesDir string) (*InstallResult, error)

Install performs the actual installation of dotfiles by creating symlinks and generating template files

func InstallWithConfig

func InstallWithConfig(modules []config.ModuleConfig, config *InstallConfig) (*InstallResult, error)

InstallWithConfig performs installation using the provided configuration

type InstallationError

type InstallationError struct {
	Operation string
	Source    string
	Target    string
	Cause     error
}

InstallationError represents an error that occurred during installation

func (*InstallationError) Error

func (e *InstallationError) Error() string

Error implements the error interface

func (*InstallationError) Unwrap

func (e *InstallationError) Unwrap() error

Unwrap returns the underlying cause

type Installer

type Installer struct {
	// contains filtered or unexported fields
}

Installer handles the installation of dotfiles

func NewInstaller

func NewInstaller(fileOp filesystem.FileOperator, templateRenderer template.TemplateRenderer, stateMgr state.StateManager) *Installer

NewInstaller creates a new Installer instance

func (*Installer) Install

func (i *Installer) Install(req *InstallRequest) (*InstallResult, error)

Install performs the installation of dotfiles

type MockFileOperator

type MockFileOperator struct {
	CreateSymlinkFunc   func(source, target string) error
	RemoveFileFunc      func(path string) error
	CreateBackupFunc    func(path string) (string, error)
	EnsureDirectoryFunc func(path string) error
	CopyFileFunc        func(src, dst string) error
	FileExistsFunc      func(path string) bool
	IsSymlinkFunc       func(path string) bool
	ReadlinkFunc        func(path string) (string, error)
	WriteFileFunc       func(path string, data []byte, perm os.FileMode) error
}

MockFileOperator is a mock implementation of filesystem.FileOperator

func (*MockFileOperator) CopyFile

func (m *MockFileOperator) CopyFile(src, dst string) error

func (*MockFileOperator) CreateBackup

func (m *MockFileOperator) CreateBackup(path string) (string, error)
func (m *MockFileOperator) CreateSymlink(source, target string) error

func (*MockFileOperator) EnsureDirectory

func (m *MockFileOperator) EnsureDirectory(path string) error

func (*MockFileOperator) FileExists

func (m *MockFileOperator) FileExists(path string) bool
func (m *MockFileOperator) IsSymlink(path string) bool
func (m *MockFileOperator) Readlink(path string) (string, error)

func (*MockFileOperator) RemoveFile

func (m *MockFileOperator) RemoveFile(path string) error

func (*MockFileOperator) WriteFile

func (m *MockFileOperator) WriteFile(path string, data []byte, perm os.FileMode) error

type MockStateManager

type MockStateManager struct {
	LoadFunc           func(path string) (*dotmanState.StateFile, error)
	SaveFunc           func(path string, stateFile *dotmanState.StateFile) error
	AddMappingFunc     func(stateFile *dotmanState.StateFile, source, target, fileType string) error
	RemoveMappingsFunc func(stateFile *dotmanState.StateFile, targets []string) error
}

MockStateManager is a mock implementation of state.StateManager

func (*MockStateManager) AddMapping

func (m *MockStateManager) AddMapping(stateFile *dotmanState.StateFile, source, target, fileType string) error

func (*MockStateManager) Load

func (*MockStateManager) RemoveMappings

func (m *MockStateManager) RemoveMappings(stateFile *dotmanState.StateFile, targets []string) error

func (*MockStateManager) Save

func (m *MockStateManager) Save(path string, stateFile *dotmanState.StateFile) error

type MockTemplateRenderer

type MockTemplateRenderer struct {
	RenderFunc   func(templatePath string, vars map[string]string) ([]byte, error)
	ValidateFunc func(templatePath string, vars map[string]string) error
}

MockTemplateRenderer is a mock implementation of template.TemplateRenderer

func (*MockTemplateRenderer) Render

func (m *MockTemplateRenderer) Render(templatePath string, vars map[string]string) ([]byte, error)

func (*MockTemplateRenderer) Validate

func (m *MockTemplateRenderer) Validate(templatePath string, vars map[string]string) error

type OperationResult

type OperationResult struct {
	Type     OperationType          `json:"type"`
	Source   string                 `json:"source"`
	Target   string                 `json:"target"`
	Success  bool                   `json:"success"`
	Error    error                  `json:"error,omitempty"`
	Metadata map[string]interface{} `json:"metadata,omitempty"`
}

OperationResult unified result type for all operations

type OperationType

type OperationType string

OperationType represents the type of operation performed

const (
	OperationCreateLink     OperationType = "create_link"
	OperationCreateTemplate OperationType = "create_template"
	OperationForceLink      OperationType = "force_link"
	OperationForceTemplate  OperationType = "force_template"
	OperationSkip           OperationType = "skip"
)

type ResultSummary

type ResultSummary struct {
	Total      int      `json:"total"`
	Successful int      `json:"successful"`
	Failed     int      `json:"failed"`
	Skipped    int      `json:"skipped"`
	Errors     []string `json:"errors,omitempty"`
}

ResultSummary for consistent reporting across operations

func (*ResultSummary) AddResult

func (rs *ResultSummary) AddResult(result OperationResult)

AddResult adds a result to the summary

func (*ResultSummary) AddSkipped

func (rs *ResultSummary) AddSkipped()

AddSkipped increments the skipped count

func (*ResultSummary) HasErrors

func (rs *ResultSummary) HasErrors() bool

HasErrors returns true if there are any errors

func (*ResultSummary) SuccessRate

func (rs *ResultSummary) SuccessRate() float64

SuccessRate returns the success rate as a percentage

type SymlinkValidationResult

type SymlinkValidationResult struct {
	IsValid bool
	Reason  string
}

SymlinkValidationResult contains the result of symlink validation

type UninstallConfig

type UninstallConfig struct {
	BackupModified bool   `json:"backup_modified"`
	StatePath      string `json:"state_path"`
}

UninstallConfig contains configuration for uninstall operations

type UninstallRequest

type UninstallRequest struct {
	DotfilesDir    string
	BackupModified bool
}

UninstallRequest contains the request parameters for uninstallation

type UninstallResult

type UninstallResult struct {
	IsSuccess         bool
	Summary           string
	Errors            []string
	RemovedLinks      []FileOperation
	SkippedLinks      []OperationResult
	RemovedGenerated  []FileOperation
	SkippedGenerated  []OperationResult
	BackedUpGenerated []OperationResult
	FailedRemovals    []OperationResult
}

UninstallResult contains the results of an uninstallation

func Uninstall

func Uninstall(dotfilesDir string) (*UninstallResult, error)

Uninstall performs the uninstallation of dotfiles using the state file

func UninstallWithConfig

func UninstallWithConfig(config *UninstallConfig) (*UninstallResult, error)

UninstallWithConfig performs uninstallation using the provided configuration

type Uninstaller

type Uninstaller struct {
	// contains filtered or unexported fields
}

Uninstaller handles uninstallation operations with dependency injection

func NewUninstaller

func NewUninstaller(fileOp filesystem.FileOperator, stateMgr state.StateManager) *Uninstaller

NewUninstaller creates a new Uninstaller instance

func (*Uninstaller) Uninstall

func (u *Uninstaller) Uninstall(req *UninstallRequest) (*UninstallResult, error)

Uninstall performs the uninstallation of dotfiles using the state file

type ValidateResult

type ValidateResult struct {
	IsValid bool
	Summary string
	Errors  []string
	// Grouped operations by type
	CreateOperations    []FileOperation
	CreateTemplateOps   []FileOperation
	ForceLinkOperations []FileOperation
	ForceTemplateOps    []FileOperation
	SkipOperations      []FileOperation
}

ValidateResult contains the complete results of a dry run

func Validate

func Validate(modules []config.ModuleConfig, vars map[string]string, mkdir bool, force bool) (*ValidateResult, error)

Validate performs a complete dry-run validation and returns structured results

type ValidationError

type ValidationError struct {
	Type   string
	Path   string
	Reason string
}

ValidationError represents an error that occurred during validation

func (*ValidationError) Error

func (e *ValidationError) Error() string

Error implements the error interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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