Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrPkgNotFound = errors.New("package not found in configuration")
Functions ¶
This section is empty.
Types ¶
type Base ¶
type Base struct {
Config *models.Config
Runner runner.CommandRunner
// contains filtered or unexported fields
}
Base is the core implementation of the Controller interface.
Fields:
- Config: The user configuration containing package definitions
- installedPkgs: A cache of installed packages to avoid repeated checks
- Runner: A CommandRunner instance to execute system commands
It stores the user configuration, the internal cache of installed packages, and uses a CommandRunner to interact with the underlying system.
func NewBase ¶
func NewBase(config *models.Config, r runner.CommandRunner) *Base
NewBase instantiates a new Base struct.
Parameters:
- config: the main configuration struct loaded by the user
- r: command runner abstraction for executing system commands
Returns:
- *Base: pointer to the new Base instance with initialized state
func (*Base) FindPackage ¶
FindPackage attempts to locate a package from the configuration based on its name.
Parameters:
- name: the name to search for (matches .Command or .Binary fields)
Returns:
- *models.Package: pointer to the matched package
- bool: true if the package was found, false otherwise
func (*Base) GetPackageName ¶
GetPackageName returns the most appropriate name to use for a package.
Parameters:
- pkg: the package whose name is to be retrieved
Returns:
- string: pkg.Binary if available, otherwise pkg.Command
func (*Base) HandlePackages ¶
func (b *Base) HandlePackages(opts PackageHandlerOptions) error
HandlePackages performs the given action on a filtered list of packages.
Parameters:
- opts: options that define which packages to act on and how
Returns:
- error: if one or more packages fail to process
Behavior:
- If opts.Packages is non-empty, only those packages are handled
- Otherwise, all packages passing FilterFunc are considered
func (*Base) IsPackageInstalled ¶
IsPackageInstalled determines whether the given package is currently installed.
Parameters:
- name: the name of the package to check
Returns:
- bool: true if the package is installed, false otherwise
Notes:
- This function lazily loads the installed package list once on first call.
type BrewSessionState ¶ added in v0.2.1
BrewSessionState holds a snapshot of brew's view of the world for a single HandlePackages run. It is intentionally small and read-only.
type Controller ¶
type Controller interface {
IsPackageInstalled(name string) bool
FindPackage(name string) *models.Package
GetPackageName(pkg *models.Package) string
}
Controller defines the behavior required for managing software packages.
Implementations of this interface must be able to:
- Check if a package is already installed
- Locate a package based on a provided name
- Retrieve the display name for a package (binary or command)
type PackageAction ¶
PackageAction describes the operation to perform on a package.
Fields:
- Name: The name of the package to operate on
- ActionVerb: The action to execute (e.g. "install", "upgrade", "uninstall")
- SkipMessage: Optional message shown when skipping a package
Description: This struct encapsulates the action to be performed on a package,
type PackageHandlerOptions ¶
type PackageHandlerOptions struct {
Action PackageAction
Packages []string
FilterFunc func(*models.Package) bool
ValidateFunc func(string) bool
AllowAdHoc bool
}
PackageHandlerOptions defines the behavior of how packages should be processed.
Fields:
- Action: The PackageAction to apply
- Packages: List of package names to target (optional)
- FilterFunc: Function to include/exclude packages from bulk operations
- ValidateFunc: Function to validate a package name before acting on it
Description: This struct allows for flexible handling of packages, including filtering
func DefaultPackageHandlerOptions ¶
func DefaultPackageHandlerOptions(action PackageAction) PackageHandlerOptions
DefaultPackageHandlerOptions returns a default configuration for handling packages.
Parameters:
- action: the action to be performed (install, upgrade, etc.)
Returns:
- PackageHandlerOptions: pre-filled options with sensible defaults
Notes:
- Skips optional packages
- Accepts all input as valid (no strict validation)