Files
snack/snap/snap.go
copilot-swe-agent[bot] 34578efcad Update all package managers to return InstallResult/RemoveResult
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>
2026-02-28 06:31:01 +00:00

86 lines
2.2 KiB
Go

// Package snap provides Go bindings for the snap package manager.
package snap
import (
"context"
"github.com/gogrlx/snack"
)
// Snap wraps the snap CLI.
type Snap struct {
snack.Locker
}
// New returns a new Snap manager.
func New() *Snap {
return &Snap{}
}
// Name returns "snap".
func (s *Snap) Name() string { return "snap" }
// Available reports whether snap is present on the system.
func (s *Snap) Available() bool { return available() }
// Install one or more packages.
func (s *Snap) Install(ctx context.Context, pkgs []snack.Target, opts ...snack.Option) (snack.InstallResult, error) {
s.Lock()
defer s.Unlock()
return install(ctx, pkgs, opts...)
}
// Remove one or more packages.
func (s *Snap) Remove(ctx context.Context, pkgs []snack.Target, opts ...snack.Option) (snack.RemoveResult, error) {
s.Lock()
defer s.Unlock()
return remove(ctx, pkgs, opts...)
}
// Purge removes packages including all data.
func (s *Snap) Purge(ctx context.Context, pkgs []snack.Target, opts ...snack.Option) error {
s.Lock()
defer s.Unlock()
return purge(ctx, pkgs, opts...)
}
// Upgrade all installed snaps.
func (s *Snap) Upgrade(ctx context.Context, opts ...snack.Option) error {
s.Lock()
defer s.Unlock()
return upgrade(ctx, opts...)
}
// Update checks for available updates (snap auto-refreshes).
func (s *Snap) Update(ctx context.Context) error {
return update(ctx)
}
// List returns all installed snaps.
func (s *Snap) List(ctx context.Context) ([]snack.Package, error) {
return list(ctx)
}
// Search queries the snap store.
func (s *Snap) Search(ctx context.Context, query string) ([]snack.Package, error) {
return search(ctx, query)
}
// Info returns details about a specific snap.
func (s *Snap) Info(ctx context.Context, pkg string) (*snack.Package, error) {
return info(ctx, pkg)
}
// IsInstalled reports whether a snap is currently installed.
func (s *Snap) IsInstalled(ctx context.Context, pkg string) (bool, error) {
return isInstalled(ctx, pkg)
}
// Version returns the installed version of a snap.
func (s *Snap) Version(ctx context.Context, pkg string) (string, error) {
return version(ctx, pkg)
}
// Verify interface compliance at compile time.
var _ snack.Manager = (*Snap)(nil)