mirror of
https://github.com/gogrlx/snack.git
synced 2026-04-02 05:08:42 -07:00
Change Install and Remove method signatures across all package manager
implementations (apt, apk, dnf, pacman, rpm, dpkg, snap, flatpak, ports,
pkg) to match the updated Manager interface.
- Wrapper files: update Install/Remove to return (snack.InstallResult, error)
and (snack.RemoveResult, error) respectively
- Platform files (_linux.go, _openbsd.go, _freebsd.go): implement pre-check
logic using isInstalled() to classify packages as unchanged or to-process,
run command on actionable packages only, then collect results with version()
- Stub files (_other.go): return (snack.InstallResult{}, ErrUnsupportedPlatform)
and (snack.RemoveResult{}, ErrUnsupportedPlatform)
- DNF special case: add v5 bool parameter to internal install/remove functions
and thread d.v5 from the wrapper; update Purge to discard the result
- cmd/snack/main.go: update install/remove commands to discard InstallResult/
RemoveResult and return only the error to cobra
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
110 lines
3.5 KiB
Go
110 lines
3.5 KiB
Go
package snack
|
|
|
|
// InstallResult holds the outcome of an Install operation.
|
|
type InstallResult struct {
|
|
// Installed contains packages that were newly installed by this operation.
|
|
Installed []Package
|
|
// Updated contains packages that were upgraded by this operation.
|
|
Updated []Package
|
|
// Unchanged contains the names of packages that were already at the
|
|
// desired state and required no action.
|
|
Unchanged []string
|
|
}
|
|
|
|
// RemoveResult holds the outcome of a Remove operation.
|
|
type RemoveResult struct {
|
|
// Removed contains packages that were removed by this operation.
|
|
Removed []Package
|
|
// Unchanged contains the names of packages that were not installed
|
|
// and required no action.
|
|
Unchanged []string
|
|
}
|
|
|
|
// Package represents a system package.
|
|
type Package struct {
|
|
Name string `json:"name"`
|
|
Version string `json:"version"`
|
|
Description string `json:"description,omitempty"`
|
|
Arch string `json:"arch,omitempty"`
|
|
Repository string `json:"repository,omitempty"`
|
|
Installed bool `json:"installed"`
|
|
}
|
|
|
|
// Options holds configuration for package manager operations.
|
|
type Options struct {
|
|
Sudo bool
|
|
AssumeYes bool
|
|
DryRun bool
|
|
Root string // alternate root filesystem
|
|
Verbose bool
|
|
Refresh bool // refresh package index before operation
|
|
FromRepo string // constrain operation to a specific repository
|
|
Reinstall bool // reinstall already-installed packages
|
|
}
|
|
|
|
// Option is a functional option for package manager operations.
|
|
type Option func(*Options)
|
|
|
|
// WithSudo runs the command with sudo.
|
|
func WithSudo() Option {
|
|
return func(o *Options) { o.Sudo = true }
|
|
}
|
|
|
|
// WithAssumeYes automatically confirms prompts.
|
|
func WithAssumeYes() Option {
|
|
return func(o *Options) { o.AssumeYes = true }
|
|
}
|
|
|
|
// WithDryRun simulates the operation without making changes.
|
|
func WithDryRun() Option {
|
|
return func(o *Options) { o.DryRun = true }
|
|
}
|
|
|
|
// WithRoot sets an alternate root filesystem path.
|
|
func WithRoot(root string) Option {
|
|
return func(o *Options) { o.Root = root }
|
|
}
|
|
|
|
// WithVerbose enables verbose output.
|
|
func WithVerbose() Option {
|
|
return func(o *Options) { o.Verbose = true }
|
|
}
|
|
|
|
// WithRefresh refreshes the package database before the operation.
|
|
// Equivalent to pacman -Sy, apt-get update, apk update, etc.
|
|
func WithRefresh() Option {
|
|
return func(o *Options) { o.Refresh = true }
|
|
}
|
|
|
|
// WithFromRepo constrains the operation to a specific repository.
|
|
// e.g. "unstable" for apt, "community" for pacman.
|
|
func WithFromRepo(repo string) Option {
|
|
return func(o *Options) { o.FromRepo = repo }
|
|
}
|
|
|
|
// WithReinstall forces reinstallation of already-installed packages.
|
|
func WithReinstall() Option {
|
|
return func(o *Options) { o.Reinstall = true }
|
|
}
|
|
|
|
// Repository represents a configured package repository.
|
|
type Repository struct {
|
|
ID string `json:"id"` // unique identifier
|
|
Name string `json:"name,omitempty"` // human-readable name
|
|
URL string `json:"url"` // repository URL
|
|
Enabled bool `json:"enabled"` // whether the repo is active
|
|
GPGCheck bool `json:"gpg_check,omitempty"` // whether GPG verification is enabled
|
|
GPGKey string `json:"gpg_key,omitempty"` // GPG key URL or ID
|
|
Type string `json:"type,omitempty"` // e.g. "deb", "rpm-md", "pkg"
|
|
Arch string `json:"arch,omitempty"` // architecture filter
|
|
}
|
|
|
|
// ApplyOptions processes functional options into an Options struct.
|
|
func ApplyOptions(opts ...Option) Options {
|
|
var o Options
|
|
for _, opt := range opts {
|
|
opt(&o)
|
|
}
|
|
return o
|
|
}
|