unexport ser/systemd | fixes (golint)
This commit is contained in:
parent
798a847ca7
commit
235e30aeb7
3
args.go
3
args.go
|
@ -6,6 +6,9 @@ import (
|
|||
"git.xdrm.io/go/nix-amer/internal/instruction"
|
||||
)
|
||||
|
||||
// GetArgs manages cli arguments to build executionContext,
|
||||
// extract the buildfile path and return whether to dry-run/execute
|
||||
// + adds error information
|
||||
func GetArgs() (*instruction.ExecutionContext, string, bool, error) {
|
||||
setupFlags(flag.CommandLine)
|
||||
|
||||
|
|
|
@ -5,11 +5,13 @@ import (
|
|||
"git.xdrm.io/go/nix-amer/internal/clifmt"
|
||||
)
|
||||
|
||||
// LineError wraps errors with a line index
|
||||
type LineError struct {
|
||||
Line int
|
||||
Err error
|
||||
}
|
||||
|
||||
// Error implements Error
|
||||
func (le LineError) Error() string {
|
||||
return fmt.Sprintf(":%d %s", le.Line, clifmt.Color(31, le.Err.Error()))
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
// ErrNullContext is raised when the given context is nil
|
||||
var ErrNullContext = errors.New("null context")
|
||||
|
||||
// Reader is the buildfile reader
|
||||
|
|
|
@ -8,7 +8,10 @@ import (
|
|||
"path/filepath"
|
||||
)
|
||||
|
||||
// ErrUnknownExtension is raised when encountering an unknown extension
|
||||
var ErrUnknownExtension = errors.New("unknown extension format")
|
||||
|
||||
// ErrUnknownFormat is raised when the format cannot be guessed from the content of the file
|
||||
var ErrUnknownFormat = errors.New("cannot infer format from content")
|
||||
|
||||
// Load the current file and create the configuration format accordingly
|
||||
|
|
|
@ -7,7 +7,9 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
var ErrImpossible = fmt.Errorf("cannot update configuration")
|
||||
// ErrCannotSet is raised when there is an error trying to update
|
||||
// a field
|
||||
var ErrCannotSet = fmt.Errorf("cannot set the field")
|
||||
|
||||
type config struct {
|
||||
raw string
|
||||
|
@ -63,7 +65,7 @@ func (d config) Exec(ctx ExecutionContext) ([]byte, error) {
|
|||
|
||||
// 2. try to update value
|
||||
if !format.Set(d.Path, d.Value) {
|
||||
return nil, ErrImpossible
|
||||
return nil, ErrCannotSet
|
||||
}
|
||||
|
||||
// 3. Update file
|
||||
|
|
|
@ -16,6 +16,7 @@ type T interface {
|
|||
Exec(ExecutionContext) ([]byte, error)
|
||||
}
|
||||
|
||||
// ExecutionContext contains system-specific drivers to manage the host
|
||||
type ExecutionContext struct {
|
||||
PackageManager pkg.PackageManager
|
||||
ServiceManager ser.ServiceManager
|
||||
|
|
|
@ -4,5 +4,9 @@ import (
|
|||
"errors"
|
||||
)
|
||||
|
||||
// ErrInvalidSyntax is raised when encountering an invalid token
|
||||
var ErrInvalidSyntax = errors.New("invalid instruction format")
|
||||
|
||||
// ErrUnknownInstruction is raised when encountering an unknown instruction
|
||||
// it can mean that you're not using the right version or that you've misspelled it
|
||||
var ErrUnknownInstruction = errors.New("unknown instruction")
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package pkg
|
||||
|
||||
// DefaultManager if not empty is the default package-manager to use when missing
|
||||
var DefaultManager = ""
|
||||
|
||||
// PackageManager is the common interface for all package-manager drivers (e.g. `dpkg` for debian-based, `pacman` for arch)
|
||||
|
|
|
@ -4,9 +4,15 @@ import (
|
|||
"errors"
|
||||
)
|
||||
|
||||
// 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) (PackageManager, error) {
|
||||
|
||||
// 1. create manager (fail if unknown)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package ser
|
||||
|
||||
// DefaultManager if not empty is the default service-manager to use when missing
|
||||
var DefaultManager = "systemd"
|
||||
|
||||
// ServiceManager is the common interface for service managers (systemd, init.d)
|
||||
|
|
|
@ -4,4 +4,5 @@ import (
|
|||
"errors"
|
||||
)
|
||||
|
||||
// ErrUnknownAction is raised when an unknown action is called (enable, start, ...)
|
||||
var ErrUnknownAction = errors.New("unknown action")
|
||||
|
|
|
@ -4,16 +4,22 @@ import (
|
|||
"errors"
|
||||
)
|
||||
|
||||
// ErrUnknownManager is raised when the asked manager does not exist
|
||||
var ErrUnknownManager = errors.New("unknown service manager")
|
||||
var ErrNotInstalled = errors.New("not candidate installed")
|
||||
|
||||
// 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) (ServiceManager, error) {
|
||||
|
||||
// 1. create manager (fail if unknown)
|
||||
var manager ServiceManager
|
||||
switch _manager {
|
||||
case "systemd":
|
||||
manager = new(Systemd)
|
||||
manager = new(systemd)
|
||||
default:
|
||||
return nil, ErrUnknownManager
|
||||
}
|
||||
|
|
|
@ -4,14 +4,14 @@ import (
|
|||
"os/exec"
|
||||
)
|
||||
|
||||
type Systemd struct{}
|
||||
type systemd struct{}
|
||||
|
||||
// available actions
|
||||
var actions = []string{"enable", "disable", "start", "stop", "reload", "restart"}
|
||||
|
||||
func (d Systemd) Name() string { return "systemctl" }
|
||||
func (d systemd) Name() string { return "systemctl" }
|
||||
|
||||
func (d Systemd) Exec(action, service string) error {
|
||||
func (d systemd) Exec(action, service string) error {
|
||||
|
||||
// 1. fail if unknown action
|
||||
known := false
|
||||
|
|
Loading…
Reference in New Issue