patch

package
v0.0.0-...-40cbffd Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: Apache-2.0 Imports: 42 Imported by: 0

Documentation

Overview

Package patch implements the patch command functionality

Package patch exposes the distribution patch flow to the app layer.

Index

Constants

This section is empty.

Variables

View Source
var (
	DistributionFlag string
)

Re-export flags

Functions

func InitFlags

func InitFlags()

InitFlags initializes the flags for the patch command

Types

type CommandHandler

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

CommandHandler manages the state and logic for the patch command

func NewCommandHandler

func NewCommandHandler(opts *CommandHandlerOptions) *CommandHandler

NewCommandHandler creates a new patch handler

func (*CommandHandler) BaseURL

func (h *CommandHandler) BaseURL() string

BaseURL returns the base URL.

func (*CommandHandler) Cleanup

func (h *CommandHandler) Cleanup() error

Cleanup performs cleanup tasks

func (*CommandHandler) DataProvider

func (h *CommandHandler) DataProvider() repository.PatchProvider

DataProvider returns the data provider from state.

func (*CommandHandler) DeleteDirectoryPaths

func (h *CommandHandler) DeleteDirectoryPaths() []string

DeleteDirectoryPaths returns remote directory paths to delete recursively.

func (*CommandHandler) DeletePaths

func (h *CommandHandler) DeletePaths() []string

DeletePaths returns remote paths to delete.

func (*CommandHandler) DistributionName

func (h *CommandHandler) DistributionName() string

DistributionName returns the distribution name option.

func (*CommandHandler) DryRun

func (h *CommandHandler) DryRun() bool

DryRun returns whether dry run mode is enabled.

func (*CommandHandler) DryRunMode

func (h *CommandHandler) DryRunMode() string

DryRunMode returns the dry run mode string.

func (*CommandHandler) Execute

func (h *CommandHandler) Execute(ctx context.Context) error

Execute performs the patch process using the DataProvider, delegating to PatchService.

func (*CommandHandler) ExecutionSummary

func (h *CommandHandler) ExecutionSummary() ExecutionSummary

ExecutionSummary returns aggregate statistics from the latest execution.

func (*CommandHandler) FilePaths

func (h *CommandHandler) FilePaths() []string

FilePaths returns the file paths to patch.

func (*CommandHandler) Message

func (h *CommandHandler) Message() string

Message returns the commit message.

func (*CommandHandler) MovePaths

func (h *CommandHandler) MovePaths() []string

MovePaths returns move specifications.

func (*CommandHandler) PlannedChanges

func (h *CommandHandler) PlannedChanges() map[string]*TargetChanges

PlannedChanges returns the planned changes map.

func (*CommandHandler) Proposal

func (h *CommandHandler) Proposal(ctx context.Context) (bool, error)

Proposal calculates the patch plan and asks for user confirmation

func (*CommandHandler) Provider

func (h *CommandHandler) Provider() string

Provider returns the provider option.

func (*CommandHandler) SetDataProvider

func (h *CommandHandler) SetDataProvider(provider repository.PatchProvider)

SetDataProvider sets the data provider (for testing).

func (*CommandHandler) SetDryRun

func (h *CommandHandler) SetDryRun(dryRun bool)

SetDryRun sets the dry run mode (for testing).

func (*CommandHandler) SetDryRunMode

func (h *CommandHandler) SetDryRunMode(mode string)

SetDryRunMode sets the dry run mode string (for testing).

func (*CommandHandler) SetWarnUnresolved

func (h *CommandHandler) SetWarnUnresolved(value string)

SetWarnUnresolved sets the warn-unresolved setting (for testing).

func (*CommandHandler) SetWorkingDir

func (h *CommandHandler) SetWorkingDir(dir string)

SetWorkingDir sets the working directory (for testing).

func (*CommandHandler) Setup

func (h *CommandHandler) Setup(ctx context.Context) error

Setup initializes the patch process

func (*CommandHandler) SkipConfirmation

func (h *CommandHandler) SkipConfirmation() bool

SkipConfirmation returns whether to skip user confirmation.

func (*CommandHandler) Token

func (h *CommandHandler) Token() string

Token returns the token.

func (*CommandHandler) UserInput

func (h *CommandHandler) UserInput() userinput.UserInput

UserInput returns the user input dependency.

func (*CommandHandler) Validate

func (h *CommandHandler) Validate() error

Validate checks if the configuration is set and valid

func (*CommandHandler) Validated

func (h *CommandHandler) Validated() bool

Validated returns whether the handler has been validated.

func (*CommandHandler) WarnUnresolved

func (h *CommandHandler) WarnUnresolved() string

WarnUnresolved returns the warn-unresolved setting.

func (*CommandHandler) WorkingDir

func (h *CommandHandler) WorkingDir() string

WorkingDir returns the working directory from state.

type CommandHandlerOptions

type CommandHandlerOptions struct {
	FilePaths                    []string
	PatchContent                 repository.RepositoryContent
	DeletePaths                  []string
	DeleteDirectoryPaths         []string
	MovePaths                    []string
	TargetNames                  []string
	TargetUUIDs                  []string
	TargetMembers                []string
	Token                        string
	BaseURL                      string
	Provider                     string
	DistributionName             string
	WorkingDir                   string
	Message                      string
	DryRun                       bool
	DryRunMode                   string
	WarnUnresolved               string
	Force                        bool
	SkipConfirmation             bool
	SuppressOutput               bool
	DisableEvalPagesUniqueDomain bool

	// Worker pool overrides
	WorkersOverride     int
	RateLimitOverride   float64
	TaskTimeoutOverride time.Duration
	WorkersSet          bool
	RateLimitSet        bool
	TaskTimeoutSet      bool

	// Optional dependencies for testing
	UserInput        userinput.UserInput
	PatchService     patching.PatchService
	TemplateService  individualization.TemplateService
	ProgressReporter svc.ProgressReporter
}

CommandHandlerOptions contains options for creating a new patch CommandHandler (public, for cmd/)

type Error

Error is a type alias for the generic CommandError.

func NewApplyChangesError

func NewApplyChangesError(err error) *Error

NewApplyChangesError creates an error for change application failures.

func NewCommitChangesError

func NewCommitChangesError(targetName string, projectID int, uuid string, err error) *Error

NewCommitChangesError creates an error for commit failures.

func NewConfigLoadError

func NewConfigLoadError(err error) *Error

NewConfigLoadError creates an error for config loading failures.

func NewConfirmationPromptError

func NewConfirmationPromptError(err error) *Error

NewConfirmationPromptError creates an error for confirmation prompt failures.

func NewCreateAdapterError

func NewCreateAdapterError() *Error

NewCreateAdapterError creates an error for adapter creation failures.

func NewCreateProviderError

func NewCreateProviderError(providerType string, err error) *Error

NewCreateProviderError creates an error for provider creation failures.

func NewDataProviderConfigError

func NewDataProviderConfigError(baseURL string) *Error

NewDataProviderConfigError creates an error for data provider config failures.

func NewDataProviderNilError

func NewDataProviderNilError() *Error

NewDataProviderNilError creates an error for nil data provider.

func NewDistributionNotFoundError

func NewDistributionNotFoundError(distributionName string) *Error

NewDistributionNotFoundError creates an error for missing distribution.

func NewDistributionSelectionError

func NewDistributionSelectionError(err error) *Error

NewDistributionSelectionError creates an error for distribution selection failures.

func NewError

func NewError(errorType ErrorType, message string, err error) *Error

NewError creates a new Error (kept for backward compatibility).

func NewExecutionErrorsError

func NewExecutionErrorsError(errorCount int) *Error

NewExecutionErrorsError creates an error for execution errors.

func NewFindIndividualConfigError

func NewFindIndividualConfigError(uuid string, projectID int, err error) *Error

NewFindIndividualConfigError creates an error for individual config finding failures.

func NewGetProjectError

func NewGetProjectError(err error) *Error

NewGetProjectError creates an error for project fetch failures.

func NewIndividualizationError

func NewIndividualizationError(err error) *Error

NewIndividualizationError creates an error for individualization failures.

func NewIndividualizeContentError

func NewIndividualizeContentError(targetName string, projectID int, uuid string, file string, err error) *Error

NewIndividualizeContentError creates an error for content individualization failures.

func NewIndividualsConfigNotFoundError

func NewIndividualsConfigNotFoundError(configPath string) *Error

NewIndividualsConfigNotFoundError creates an error for missing individuals config.

func NewInitializeClientError

func NewInitializeClientError(err error) *Error

NewInitializeClientError creates an error for client initialization failures.

func NewInitializeProviderError

func NewInitializeProviderError(providerType string, err error) *Error

NewInitializeProviderError creates an error for provider initialization failures.

func NewInvalidMoveSpecError

func NewInvalidMoveSpecError(spec string) *Error

NewInvalidMoveSpecError creates an error for invalid move specifications.

func NewInvalidPatchPathError

func NewInvalidPatchPathError(path string, err error) *Error

NewInvalidPatchPathError creates an error for invalid remote patch paths.

func NewListDistributionsError

func NewListDistributionsError(err error) *Error

NewListDistributionsError creates an error for distribution listing failures.

func NewListLocalSnapshotsError

func NewListLocalSnapshotsError(localRoot string, err error) *Error

NewListLocalSnapshotsError creates an error for local snapshot discovery failures.

func NewLoadDistributionConfigError

func NewLoadDistributionConfigError(configPath string, err error) *Error

NewLoadDistributionConfigError creates an error for distribution config loading failures.

func NewLoadIndividualsConfigError

func NewLoadIndividualsConfigError(err error) *Error

NewLoadIndividualsConfigError creates an error for individuals config loading failures.

func NewLoadIndividualsConfigNotFoundError

func NewLoadIndividualsConfigNotFoundError(configPath string, err error) *Error

NewLoadIndividualsConfigNotFoundError creates an error for missing individuals config.

func NewLoadRemotesConfigError

func NewLoadRemotesConfigError(err error) *Error

NewLoadRemotesConfigError creates an error for remotes config loading failures.

func NewNoClientFoundError

func NewNoClientFoundError(targetName string) *Error

NewNoClientFoundError creates an error for missing client.

func NewNoDistributionsFoundError

func NewNoDistributionsFoundError(workingDir string) *Error

NewNoDistributionsFoundError creates an error for missing distributions.

func NewNoFilesSpecifiedError

func NewNoFilesSpecifiedError() *Error

NewNoFilesSpecifiedError creates an error when no files are specified.

func NewNoIndividualFoundError

func NewNoIndividualFoundError(uuid string) *Error

NewNoIndividualFoundError creates an error for missing individual.

func NewNoLocalSnapshotFoundError

func NewNoLocalSnapshotFoundError(localRoot string) *Error

NewNoLocalSnapshotFoundError creates an error when no usable local snapshot exists.

func NewNoMemberFoundError

func NewNoMemberFoundError(projectName string, uuid string) *Error

NewNoMemberFoundError creates an error for missing member.

func NewNoRemoteProjectsError

func NewNoRemoteProjectsError() *Error

NewNoRemoteProjectsError creates an error for missing remote projects.

func NewNoRemotesFoundError

func NewNoRemotesFoundError(targetName string) *Error

NewNoRemotesFoundError creates an error for missing remotes.

func NewNoTargetsFoundError

func NewNoTargetsFoundError(configPath string) *Error

NewNoTargetsFoundError creates an error for missing targets.

func NewNoValidPatchFilesError

func NewNoValidPatchFilesError() *Error

NewNoValidPatchFilesError creates an error when no valid patch files are found.

func NewOriginConfigNotLoadedError

func NewOriginConfigNotLoadedError() *Error

NewOriginConfigNotLoadedError creates an error for unloaded origin config.

func NewOriginConfigVersionMissingError

func NewOriginConfigVersionMissingError() *Error

NewOriginConfigVersionMissingError creates an error for missing origin config version.

func NewPatchCancelledError

func NewPatchCancelledError() *Error

NewPatchCancelledError creates an error for patch cancellation.

func NewPatchTargetError

func NewPatchTargetError(targetName string, projectID int, err error) *Error

NewPatchTargetError creates an error for patch target failures.

func NewPathResolutionError

func NewPathResolutionError(path string, err error) *Error

NewPathResolutionError creates an error for path resolution failures.

func NewPlanCalculationError

func NewPlanCalculationError(file string, uuid string, err error) *Error

NewPlanCalculationError creates an error for plan calculation failures.

func NewProposalCancelledError

func NewProposalCancelledError(msg string) *Error

NewProposalCancelledError creates an error for proposal cancellation.

func NewProviderConnectionError

func NewProviderConnectionError(err error) *Error

NewProviderConnectionError creates an error for provider connection failures.

func NewReadFileError

func NewReadFileError(filename string, err error) *Error

NewReadFileError creates an error for file read failures.

func NewRemoteKeyMissingError

func NewRemoteKeyMissingError(targetName string) *Error

NewRemoteKeyMissingError creates an error for missing remote key.

func NewResolveCredentialsError

func NewResolveCredentialsError(targetName string, err error) *Error

NewResolveCredentialsError creates an error for credential resolution failures.

func NewUserCancelledError

func NewUserCancelledError() *Error

NewUserCancelledError creates an error for user cancellation.

func NewUserConfirmationError

func NewUserConfirmationError(err error) *Error

NewUserConfirmationError creates an error for user confirmation failures.

func NewWorkingDirAccessError

func NewWorkingDirAccessError(err error) *Error

NewWorkingDirAccessError creates an error for working directory access failures.

type ErrorType

type ErrorType int

ErrorType defines domain-based error categories for the patch package. Consolidated from 41+ specific types to 8 semantic domains.

const (
	// ErrValidation indicates input validation errors.
	ErrValidation ErrorType = iota

	// ErrUserCancelled indicates user-initiated cancellation.
	ErrUserCancelled

	// ErrFilesystem indicates file system operation errors.
	ErrFilesystem

	// ErrConfig indicates configuration loading errors.
	ErrConfig

	// ErrNotFound indicates missing resources.
	ErrNotFound

	// ErrProvider indicates provider/client errors.
	ErrProvider

	// ErrProcess indicates processing or execution errors.
	ErrProcess

	// ErrCredential indicates credential resolution errors.
	ErrCredential
)

func (ErrorType) String

func (t ErrorType) String() string

String returns a human-readable name for the error type.

type ExecutionSummary

type ExecutionSummary struct {
	SuccessCount int
	FailureCount int
	SkippedCount int
	FileCount    int
	GroupCount   int
}

ExecutionSummary contains aggregate statistics from one patch execution.

type Handler

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

Handler orchestrates patch execution.

func NewHandler

func NewHandler(opts *HandlerOptions) *Handler

NewHandler constructs a patch handler with default dependencies.

func (*Handler) Execute

func (h *Handler) Execute(ctx context.Context, req Request) (Result, error)

Execute validates, proposes, and executes a patch run.

type HandlerOptions

type HandlerOptions struct {
	NewInternalHandler newInternalHandlerFunc
}

HandlerOptions configures how the patch handler creates its internal command handler.

type ProgressTracker

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

ProgressTracker manages progress for patch operations with a single progress bar.

func NewProgressTracker

func NewProgressTracker(targets map[string]*config.TargetRemotes) *ProgressTracker

NewProgressTracker creates a new progress tracker for patch operations

func (*ProgressTracker) Abort

func (t *ProgressTracker) Abort()

Abort forcefully stops the progress bar

func (*ProgressTracker) CompleteTarget

func (t *ProgressTracker) CompleteTarget(_ string, _ bool)

CompleteTarget is called when a target completes (no-op for single bar)

func (*ProgressTracker) IncrementTarget

func (t *ProgressTracker) IncrementTarget(_ string, count int)

IncrementTarget increments the progress count

func (*ProgressTracker) StartTarget

func (t *ProgressTracker) StartTarget(_ string)

StartTarget is called when a target starts processing (no-op for single bar)

func (*ProgressTracker) Stop

func (t *ProgressTracker) Stop()

Stop ends the UI program

func (*ProgressTracker) Wait

func (t *ProgressTracker) Wait()

Wait shuts down the progress UI

type RemoteChanges

type RemoteChanges struct {
	ProjectID int
	UUID      string
	Changes   *TargetChanges
}

RemoteChanges represents changes for a single remote repository

type Request

type Request struct {
	FilePaths                    []string
	PatchContent                 repoagg.RepositoryContent
	DeletePaths                  []string
	DeleteDirectoryPaths         []string
	MovePaths                    []string
	TargetNames                  []string
	TargetUUIDs                  []string
	TargetMembers                []string
	Token                        string
	BaseURL                      string
	Provider                     string
	DistributionName             string
	WorkingDir                   string
	Message                      string
	DryRun                       bool
	DryRunMode                   string
	WarnUnresolved               string
	Force                        bool
	SkipConfirmation             bool
	SuppressOutput               bool
	DisableEvalPagesUniqueDomain bool

	WorkersOverride     int
	RateLimitOverride   float64
	TaskTimeoutOverride time.Duration
	WorkersSet          bool
	RateLimitSet        bool
	TaskTimeoutSet      bool

	UserInput        userinput.UserInput
	ProgressReporter svc.ProgressReporter
}

Request contains the input and overrides for a patch run.

type Result

type Result struct {
	Confirmed    bool
	SuccessCount int
	FailureCount int
	SkippedCount int
	FileCount    int
	GroupCount   int
}

Result reports whether the patch run was confirmed and executed.

type TargetChanges

type TargetChanges struct {
	Create            map[string][]byte   // Files to be created
	Update            map[string][]byte   // Files to be updated
	Delete            []string            // Files to be deleted
	Move              map[string]string   // Files to be moved: source -> destination
	Identical         map[string]struct{} // Files that are identical after individualization
	AdditionalActions []string            // Non-file actions that will be applied
	// DiffData stores the original content for files being updated (for diff display)
	OriginalContent map[string][]byte
}

TargetChanges holds the planned changes for a target

Jump to

Keyboard shortcuts

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