mirror of
https://github.com/gogrlx/snack.git
synced 2026-04-02 05:08:42 -07:00
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>
This commit is contained in:
@@ -24,14 +24,14 @@ func (s *Snap) Name() string { return "snap" }
|
||||
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) error {
|
||||
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) error {
|
||||
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...)
|
||||
|
||||
@@ -37,11 +37,20 @@ func run(ctx context.Context, args []string) (string, error) {
|
||||
return stdout.String(), nil
|
||||
}
|
||||
|
||||
func install(ctx context.Context, pkgs []snack.Target, opts ...snack.Option) error {
|
||||
func install(ctx context.Context, pkgs []snack.Target, opts ...snack.Option) (snack.InstallResult, error) {
|
||||
_ = snack.ApplyOptions(opts...)
|
||||
var toInstall []snack.Target
|
||||
var unchanged []string
|
||||
for _, t := range pkgs {
|
||||
ok, _ := isInstalled(ctx, t.Name)
|
||||
if ok {
|
||||
unchanged = append(unchanged, t.Name)
|
||||
} else {
|
||||
toInstall = append(toInstall, t)
|
||||
}
|
||||
}
|
||||
for _, t := range toInstall {
|
||||
args := []string{"install"}
|
||||
// Handle --classic or --channel via FromRepo
|
||||
if t.FromRepo != "" {
|
||||
if t.FromRepo == "classic" {
|
||||
args = append(args, "--classic")
|
||||
@@ -51,16 +60,39 @@ func install(ctx context.Context, pkgs []snack.Target, opts ...snack.Option) err
|
||||
}
|
||||
args = append(args, t.Name)
|
||||
if _, err := run(ctx, args); err != nil {
|
||||
return err
|
||||
return snack.InstallResult{}, err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
var installed []snack.Package
|
||||
for _, t := range toInstall {
|
||||
v, _ := version(ctx, t.Name)
|
||||
installed = append(installed, snack.Package{Name: t.Name, Version: v, Installed: true})
|
||||
}
|
||||
return snack.InstallResult{Installed: installed, Unchanged: unchanged}, nil
|
||||
}
|
||||
|
||||
func remove(ctx context.Context, pkgs []snack.Target, _ ...snack.Option) error {
|
||||
args := append([]string{"remove"}, snack.TargetNames(pkgs)...)
|
||||
_, err := run(ctx, args)
|
||||
return err
|
||||
func remove(ctx context.Context, pkgs []snack.Target, _ ...snack.Option) (snack.RemoveResult, error) {
|
||||
var toRemove []snack.Target
|
||||
var unchanged []string
|
||||
for _, t := range pkgs {
|
||||
ok, _ := isInstalled(ctx, t.Name)
|
||||
if !ok {
|
||||
unchanged = append(unchanged, t.Name)
|
||||
} else {
|
||||
toRemove = append(toRemove, t)
|
||||
}
|
||||
}
|
||||
if len(toRemove) > 0 {
|
||||
args := append([]string{"remove"}, snack.TargetNames(toRemove)...)
|
||||
if _, err := run(ctx, args); err != nil {
|
||||
return snack.RemoveResult{}, err
|
||||
}
|
||||
}
|
||||
var removed []snack.Package
|
||||
for _, t := range toRemove {
|
||||
removed = append(removed, snack.Package{Name: t.Name})
|
||||
}
|
||||
return snack.RemoveResult{Removed: removed, Unchanged: unchanged}, nil
|
||||
}
|
||||
|
||||
func purge(ctx context.Context, pkgs []snack.Target, _ ...snack.Option) error {
|
||||
|
||||
@@ -10,12 +10,12 @@ import (
|
||||
|
||||
func available() bool { return false }
|
||||
|
||||
func install(_ context.Context, _ []snack.Target, _ ...snack.Option) error {
|
||||
return snack.ErrUnsupportedPlatform
|
||||
func install(_ context.Context, _ []snack.Target, _ ...snack.Option) (snack.InstallResult, error) {
|
||||
return snack.InstallResult{}, snack.ErrUnsupportedPlatform
|
||||
}
|
||||
|
||||
func remove(_ context.Context, _ []snack.Target, _ ...snack.Option) error {
|
||||
return snack.ErrUnsupportedPlatform
|
||||
func remove(_ context.Context, _ []snack.Target, _ ...snack.Option) (snack.RemoveResult, error) {
|
||||
return snack.RemoveResult{}, snack.ErrUnsupportedPlatform
|
||||
}
|
||||
|
||||
func purge(_ context.Context, _ []snack.Target, _ ...snack.Option) error {
|
||||
|
||||
Reference in New Issue
Block a user