internal/pkg now returns 'error' instead of 'bool' for easier failure understanding

This commit is contained in:
xdrm-brackets 2018-11-08 12:52:14 +01:00
parent 5d4a47c704
commit 9fda317ad0
7 changed files with 67 additions and 75 deletions

View File

@ -8,22 +8,18 @@ type Apk struct{}
func (d Apk) Name() string { return "apk" } func (d Apk) Name() string { return "apk" }
func (d Apk) Fetch() bool { func (d Apk) Fetch() error {
_, err := exec.Command(d.Name(), "update").Output() return exec.Command(d.Name(), "update").Run()
return err == nil
} }
func (d Apk) Upgrade() bool { func (d Apk) Upgrade() error {
_, err := exec.Command(d.Name(), "upgrade").Output() return exec.Command(d.Name(), "upgrade").Run()
return err == nil
} }
func (d Apk) Install(_pkg string) bool { func (d Apk) Install(_pkg string) error {
_, err := exec.Command(d.Name(), "add", _pkg).Output() return exec.Command(d.Name(), "add", _pkg).Run()
return err == nil
} }
func (d Apk) Remove(_pkg string) bool { func (d Apk) Remove(_pkg string) error {
_, err := exec.Command(d.Name(), "del", _pkg).Output() return exec.Command(d.Name(), "del", _pkg).Run()
return err == nil
} }

View File

@ -8,33 +8,33 @@ type Apt struct{}
func (d Apt) Name() string { return "apt-get" } func (d Apt) Name() string { return "apt-get" }
func (d Apt) Fetch() bool { func (d Apt) Fetch() error {
_, err := exec.Command(d.Name(), "update").Output() err := exec.Command(d.Name(), "update").Run()
return err == nil return err
} }
func (d Apt) Upgrade() bool { func (d Apt) Upgrade() error {
_, err := exec.Command(d.Name(), "upgrade").Output() err := exec.Command(d.Name(), "upgrade").Run()
if err != nil { if err != nil {
return false return err
} }
_, err = exec.Command(d.Name(), "dist-upgrade").Output() err = exec.Command(d.Name(), "dist-upgrade").Run()
if err != nil { if err != nil {
return false return err
} }
exec.Command(d.Name(), "autoremove").Run() exec.Command(d.Name(), "autoremove").Run()
return true return nil
} }
func (d Apt) Install(_pkg string) bool { func (d Apt) Install(_pkg string) error {
_, err := exec.Command(d.Name(), "install", _pkg).Output() err := exec.Command(d.Name(), "install", _pkg).Run()
return err == nil return err
} }
func (d Apt) Remove(_pkg string) bool { func (d Apt) Remove(_pkg string) error {
_, err := exec.Command(d.Name(), "remove", _pkg).Output() err := exec.Command(d.Name(), "remove", _pkg).Run()
exec.Command(d.Name(), "autoremove").Run() exec.Command(d.Name(), "autoremove").Run()
return err == nil return err
} }

View File

@ -5,11 +5,11 @@ type PackageManager interface {
// Name of executable (to check if installed and for debug) // Name of executable (to check if installed and for debug)
Name() string Name() string
// Fetch updates the package cache/databse // Fetch updates the package cache/databse
Fetch() bool Fetch() error
// Upgrade already installed packages and whatever can be upgraded with warranty (e.g. kernel) // Upgrade already installed packages and whatever can be upgraded with warranty (e.g. kernel)
Upgrade() bool Upgrade() error
// Install a given package // Install a given package
Install(string) bool Install(string) error
// Remove a package given package // Remove a package given package
Remove(string) bool Remove(string) error
} }

View File

@ -8,23 +8,22 @@ type Dnf struct{}
func (d Dnf) Name() string { return "dnf" } func (d Dnf) Name() string { return "dnf" }
func (d Dnf) Fetch() bool { func (d Dnf) Fetch() error {
return true return nil
} }
func (d Dnf) Upgrade() bool { func (d Dnf) Upgrade() error {
_, err := exec.Command(d.Name(), "upgrade").Output() err := exec.Command(d.Name(), "upgrade").Run()
exec.Command(d.Name(), "autoremove").Run() exec.Command(d.Name(), "autoremove").Run()
return err == nil return err
} }
func (d Dnf) Install(_pkg string) bool { func (d Dnf) Install(_pkg string) error {
_, err := exec.Command(d.Name(), "install", _pkg).Output() return exec.Command(d.Name(), "install", _pkg).Run()
return err == nil
} }
func (d Dnf) Remove(_pkg string) bool { func (d Dnf) Remove(_pkg string) error {
_, err := exec.Command(d.Name(), "remove", _pkg).Output() err := exec.Command(d.Name(), "remove", _pkg).Run()
exec.Command(d.Name(), "autoremove").Run() exec.Command(d.Name(), "autoremove").Run()
return err == nil return err
} }

View File

@ -8,23 +8,23 @@ type Eopkg struct{}
func (d Eopkg) Name() string { return "eopkg" } func (d Eopkg) Name() string { return "eopkg" }
func (d Eopkg) Fetch() bool { func (d Eopkg) Fetch() error {
return true return nil
} }
func (d Eopkg) Upgrade() bool { func (d Eopkg) Upgrade() error {
_, err := exec.Command(d.Name(), "upgrade").Output() err := exec.Command(d.Name(), "upgrade").Run()
exec.Command(d.Name(), "remove-orphans").Run() exec.Command(d.Name(), "remove-orphans").Run()
return err == nil return err
} }
func (d Eopkg) Install(_pkg string) bool { func (d Eopkg) Install(_pkg string) error {
_, err := exec.Command(d.Name(), "install", _pkg).Output() err := exec.Command(d.Name(), "install", _pkg).Run()
return err == nil return err
} }
func (d Eopkg) Remove(_pkg string) bool { func (d Eopkg) Remove(_pkg string) error {
_, err := exec.Command(d.Name(), "remove", _pkg).Output() err := exec.Command(d.Name(), "remove", _pkg).Run()
exec.Command(d.Name(), "remove-orphans").Run() exec.Command(d.Name(), "remove-orphans").Run()
return err == nil return err
} }

View File

@ -8,23 +8,23 @@ type Pacman struct{}
func (d Pacman) Name() string { return "pacman" } func (d Pacman) Name() string { return "pacman" }
func (d Pacman) Fetch() bool { func (d Pacman) Fetch() error {
return true return nil
} }
func (d Pacman) Upgrade() bool { func (d Pacman) Upgrade() error {
_, err := exec.Command(d.Name(), "-Syu").Output() err := exec.Command(d.Name(), "-Syu").Run()
exec.Command(d.Name(), "-Ru").Run() exec.Command(d.Name(), "-Ru").Run()
return err == nil return err
} }
func (d Pacman) Install(_pkg string) bool { func (d Pacman) Install(_pkg string) error {
_, err := exec.Command(d.Name(), "-S", _pkg).Output() err := exec.Command(d.Name(), "-S", _pkg).Run()
return err == nil return err
} }
func (d Pacman) Remove(_pkg string) bool { func (d Pacman) Remove(_pkg string) error {
_, err := exec.Command(d.Name(), "-R", _pkg).Output() err := exec.Command(d.Name(), "-R", _pkg).Run()
exec.Command(d.Name(), "-Ru").Run() exec.Command(d.Name(), "-Ru").Run()
return err == nil return err
} }

View File

@ -8,21 +8,18 @@ type Yum struct{}
func (d Yum) Name() string { return "yum" } func (d Yum) Name() string { return "yum" }
func (d Yum) Fetch() bool { func (d Yum) Fetch() error {
return true return nil
} }
func (d Yum) Upgrade() bool { func (d Yum) Upgrade() error {
_, err := exec.Command(d.Name(), "update").Output() return exec.Command(d.Name(), "update").Run()
return err == nil
} }
func (d Yum) Install(_pkg string) bool { func (d Yum) Install(_pkg string) error {
_, err := exec.Command(d.Name(), "install", _pkg).Output() return exec.Command(d.Name(), "install", _pkg).Run()
return err == nil
} }
func (d Yum) Remove(_pkg string) bool { func (d Yum) Remove(_pkg string) error {
_, err := exec.Command(d.Name(), "remove", _pkg).Output() return exec.Command(d.Name(), "remove", _pkg).Run()
return err == nil
} }