package pkg import ( "errors" "git.xdrm.io/go/nix-amer/internal/exec" ) // ErrUnknownManager is raised when the asked manager does not exist var ErrUnknownManager = errors.New("unknown package manager") // 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") // 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 }