nix-amer/internal/ser/loader.go

37 lines
953 B
Go
Raw Permalink Normal View History

package ser
import (
"errors"
2018-11-13 12:10:55 +00:00
"github.com/xdrm-brackets/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 service manager")
2018-11-11 18:01:00 +00:00
// ErrNotInstalled is raised when the candidate service 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 service-manager by its name
func Load(_manager string, _exec exec.Executor) (ServiceManager, error) {
// 1. create manager (fail if unknown)
var manager ServiceManager
switch _manager {
case "systemd":
2018-11-11 18:01:00 +00:00
manager = new(systemd)
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
}