39 lines
718 B
Go
39 lines
718 B
Go
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(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
|
|
// }
|
|
|
|
return manager, nil
|
|
|
|
}
|