2018-11-07 10:35:04 +00:00
|
|
|
package pkg
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2018-11-13 12:10:55 +00:00
|
|
|
"github.com/xdrm-brackets/nix-amer/internal/exec"
|
2018-11-07 10:35:04 +00:00
|
|
|
)
|
|
|
|
|
2018-11-11 18:01:00 +00:00
|
|
|
// ErrUnknownManager is raised when the asked manager does not exist
|
2018-11-10 11:37:31 +00:00
|
|
|
var ErrUnknownManager = errors.New("unknown package manager")
|
2018-11-11 18:01:00 +00:00
|
|
|
|
|
|
|
// ErrNotInstalled is raised when the candidate package manager is not installed
|
|
|
|
// on the host system (use command-line -dry-run to avoid execution errors and just
|
|
|
|
// check your buildfile syntax)
|
2018-11-10 11:37:31 +00:00
|
|
|
var ErrNotInstalled = errors.New("no candidate installed")
|
2018-11-07 10:35:04 +00:00
|
|
|
|
2018-11-11 18:01:00 +00:00
|
|
|
// Load a specific package-manager by its name
|
2018-11-11 20:38:16 +00:00
|
|
|
func Load(_manager string, _exec exec.Executor) (PackageManager, error) {
|
2018-11-07 10:35:04 +00:00
|
|
|
|
2018-11-10 11:37:31 +00:00
|
|
|
// 1. create manager (fail if unknown)
|
|
|
|
var manager PackageManager
|
|
|
|
switch _manager {
|
2018-11-07 10:35:04 +00:00
|
|
|
case "apt-get":
|
2018-11-11 00:10:30 +00:00
|
|
|
manager = new(aptGet)
|
2018-11-07 10:35:04 +00:00
|
|
|
case "apk":
|
2018-11-11 00:10:30 +00:00
|
|
|
manager = new(apk)
|
2018-11-07 10:35:04 +00:00
|
|
|
case "eopkg":
|
2018-11-11 00:10:30 +00:00
|
|
|
manager = new(eopkg)
|
2018-11-07 10:35:04 +00:00
|
|
|
case "pacman":
|
2018-11-11 00:10:30 +00:00
|
|
|
manager = new(pacman)
|
2018-11-07 10:35:04 +00:00
|
|
|
case "dnf":
|
2018-11-11 00:10:30 +00:00
|
|
|
manager = new(dnf)
|
2018-11-07 10:35:04 +00:00
|
|
|
case "yum":
|
2018-11-11 00:10:30 +00:00
|
|
|
manager = new(yum)
|
2018-11-10 11:37:31 +00:00
|
|
|
default:
|
|
|
|
return nil, ErrUnknownManager
|
2018-11-07 10:35:04 +00:00
|
|
|
}
|
|
|
|
|
2018-11-10 11:37:31 +00:00
|
|
|
// 2. fail if not installed
|
|
|
|
// if exec.Command("which", manager.Name()).Run() != nil {
|
|
|
|
// return nil, ErrNotInstalled
|
|
|
|
// }
|
|
|
|
|
2018-11-11 20:38:16 +00:00
|
|
|
manager.SetExecutor(_exec)
|
2018-11-10 11:37:31 +00:00
|
|
|
return manager, nil
|
2018-11-07 10:35:04 +00:00
|
|
|
|
|
|
|
}
|