nix-amer/internal/pkg/loader.go

47 lines
1.1 KiB
Go
Raw Permalink Normal View History

package pkg
import (
"errors"
"git.xdrm.io/go/nix-amer/internal/exec"
)
2018-11-11 18:01:00 +00:00
// ErrUnknownManager is raised when the asked manager does not exist
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)
var ErrNotInstalled = errors.New("no candidate installed")
2018-11-11 18:01:00 +00:00
// Load a specific package-manager by its name
func Load(_manager string, _exec exec.Executor) (PackageManager, error) {
// 1. create manager (fail if unknown)
var manager PackageManager
switch _manager {
case "apt-get":
manager = new(aptGet)
case "apk":
manager = new(apk)
case "eopkg":
manager = new(eopkg)
case "pacman":
manager = new(pacman)
case "dnf":
manager = new(dnf)
case "yum":
manager = new(yum)
default:
return nil, ErrUnknownManager
}
// 2. fail if not installed
// if exec.Command("which", manager.Name()).Run() != nil {
// return nil, ErrNotInstalled
// }
manager.SetExecutor(_exec)
return manager, nil
}