2018-11-07 10:35:04 +00:00
|
|
|
package pkg
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
)
|
|
|
|
|
2018-11-10 11:37:31 +00:00
|
|
|
var ErrUnknownManager = errors.New("unknown package manager")
|
|
|
|
var ErrNotInstalled = errors.New("no candidate installed")
|
2018-11-07 10:35:04 +00:00
|
|
|
|
2018-11-10 11:37:31 +00:00
|
|
|
func Load(_manager string) (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-10 11:37:31 +00:00
|
|
|
manager = new(Apt)
|
2018-11-07 10:35:04 +00:00
|
|
|
case "apk":
|
2018-11-10 11:37:31 +00:00
|
|
|
manager = new(Apk)
|
2018-11-07 10:35:04 +00:00
|
|
|
case "eopkg":
|
2018-11-10 11:37:31 +00:00
|
|
|
manager = new(Eopkg)
|
2018-11-07 10:35:04 +00:00
|
|
|
case "pacman":
|
2018-11-10 11:37:31 +00:00
|
|
|
manager = new(Pacman)
|
2018-11-07 10:35:04 +00:00
|
|
|
case "dnf":
|
2018-11-10 11:37:31 +00:00
|
|
|
manager = new(Dnf)
|
2018-11-07 10:35:04 +00:00
|
|
|
case "yum":
|
2018-11-10 11:37:31 +00:00
|
|
|
manager = new(Yum)
|
|
|
|
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
|
|
|
|
// }
|
|
|
|
|
|
|
|
return manager, nil
|
2018-11-07 10:35:04 +00:00
|
|
|
|
|
|
|
}
|