nix-amer/internal/pkg/loader.go

39 lines
715 B
Go
Raw Normal View History

package pkg
import (
"errors"
)
var ErrUnknownManager = errors.New("unknown package manager")
var ErrNotInstalled = errors.New("no candidate installed")
func Load(_manager string) (PackageManager, error) {
// 1. create manager (fail if unknown)
var manager PackageManager
switch _manager {
case "apt-get":
manager = new(Apt)
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
// }
return manager, nil
}