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) Fetch() bool {
_, err := exec.Command(d.Name(), "update").Output()
return err == nil
func (d Apk) Fetch() error {
return exec.Command(d.Name(), "update").Run()
}
func (d Apk) Upgrade() bool {
_, err := exec.Command(d.Name(), "upgrade").Output()
return err == nil
func (d Apk) Upgrade() error {
return exec.Command(d.Name(), "upgrade").Run()
}
func (d Apk) Install(_pkg string) bool {
_, err := exec.Command(d.Name(), "add", _pkg).Output()
return err == nil
func (d Apk) Install(_pkg string) error {
return exec.Command(d.Name(), "add", _pkg).Run()
}
func (d Apk) Remove(_pkg string) bool {
_, err := exec.Command(d.Name(), "del", _pkg).Output()
return err == nil
func (d Apk) Remove(_pkg string) error {
return exec.Command(d.Name(), "del", _pkg).Run()
}

View File

@ -8,33 +8,33 @@ type Apt struct{}
func (d Apt) Name() string { return "apt-get" }
func (d Apt) Fetch() bool {
_, err := exec.Command(d.Name(), "update").Output()
return err == nil
func (d Apt) Fetch() error {
err := exec.Command(d.Name(), "update").Run()
return err
}
func (d Apt) Upgrade() bool {
_, err := exec.Command(d.Name(), "upgrade").Output()
func (d Apt) Upgrade() error {
err := exec.Command(d.Name(), "upgrade").Run()
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 {
return false
return err
}
exec.Command(d.Name(), "autoremove").Run()
return true
return nil
}
func (d Apt) Install(_pkg string) bool {
_, err := exec.Command(d.Name(), "install", _pkg).Output()
return err == nil
func (d Apt) Install(_pkg string) error {
err := exec.Command(d.Name(), "install", _pkg).Run()
return err
}
func (d Apt) Remove(_pkg string) bool {
_, err := exec.Command(d.Name(), "remove", _pkg).Output()
func (d Apt) Remove(_pkg string) error {
err := exec.Command(d.Name(), "remove", _pkg).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() string
// 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() bool
Upgrade() error
// Install a given package
Install(string) bool
Install(string) error
// 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) Fetch() bool {
return true
func (d Dnf) Fetch() error {
return nil
}
func (d Dnf) Upgrade() bool {
_, err := exec.Command(d.Name(), "upgrade").Output()
func (d Dnf) Upgrade() error {
err := exec.Command(d.Name(), "upgrade").Run()
exec.Command(d.Name(), "autoremove").Run()
return err == nil
return err
}
func (d Dnf) Install(_pkg string) bool {
_, err := exec.Command(d.Name(), "install", _pkg).Output()
return err == nil
func (d Dnf) Install(_pkg string) error {
return exec.Command(d.Name(), "install", _pkg).Run()
}
func (d Dnf) Remove(_pkg string) bool {
_, err := exec.Command(d.Name(), "remove", _pkg).Output()
func (d Dnf) Remove(_pkg string) error {
err := exec.Command(d.Name(), "remove", _pkg).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) Fetch() bool {
return true
func (d Eopkg) Fetch() error {
return nil
}
func (d Eopkg) Upgrade() bool {
_, err := exec.Command(d.Name(), "upgrade").Output()
func (d Eopkg) Upgrade() error {
err := exec.Command(d.Name(), "upgrade").Run()
exec.Command(d.Name(), "remove-orphans").Run()
return err == nil
return err
}
func (d Eopkg) Install(_pkg string) bool {
_, err := exec.Command(d.Name(), "install", _pkg).Output()
return err == nil
func (d Eopkg) Install(_pkg string) error {
err := exec.Command(d.Name(), "install", _pkg).Run()
return err
}
func (d Eopkg) Remove(_pkg string) bool {
_, err := exec.Command(d.Name(), "remove", _pkg).Output()
func (d Eopkg) Remove(_pkg string) error {
err := exec.Command(d.Name(), "remove", _pkg).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) Fetch() bool {
return true
func (d Pacman) Fetch() error {
return nil
}
func (d Pacman) Upgrade() bool {
_, err := exec.Command(d.Name(), "-Syu").Output()
func (d Pacman) Upgrade() error {
err := exec.Command(d.Name(), "-Syu").Run()
exec.Command(d.Name(), "-Ru").Run()
return err == nil
return err
}
func (d Pacman) Install(_pkg string) bool {
_, err := exec.Command(d.Name(), "-S", _pkg).Output()
return err == nil
func (d Pacman) Install(_pkg string) error {
err := exec.Command(d.Name(), "-S", _pkg).Run()
return err
}
func (d Pacman) Remove(_pkg string) bool {
_, err := exec.Command(d.Name(), "-R", _pkg).Output()
func (d Pacman) Remove(_pkg string) error {
err := exec.Command(d.Name(), "-R", _pkg).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) Fetch() bool {
return true
func (d Yum) Fetch() error {
return nil
}
func (d Yum) Upgrade() bool {
_, err := exec.Command(d.Name(), "update").Output()
return err == nil
func (d Yum) Upgrade() error {
return exec.Command(d.Name(), "update").Run()
}
func (d Yum) Install(_pkg string) bool {
_, err := exec.Command(d.Name(), "install", _pkg).Output()
return err == nil
func (d Yum) Install(_pkg string) error {
return exec.Command(d.Name(), "install", _pkg).Run()
}
func (d Yum) Remove(_pkg string) bool {
_, err := exec.Command(d.Name(), "remove", _pkg).Output()
return err == nil
func (d Yum) Remove(_pkg string) error {
return exec.Command(d.Name(), "remove", _pkg).Run()
}