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"
|
"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) {
|
func GetArgs() (*instruction.ExecutionContext, string, bool, error) {
|
||||||
setupFlags(flag.CommandLine)
|
setupFlags(flag.CommandLine)
|
||||||
|
|
||||||
|
|
|
@ -5,11 +5,13 @@ import (
|
||||||
"git.xdrm.io/go/nix-amer/internal/clifmt"
|
"git.xdrm.io/go/nix-amer/internal/clifmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// LineError wraps errors with a line index
|
||||||
type LineError struct {
|
type LineError struct {
|
||||||
Line int
|
Line int
|
||||||
Err error
|
Err error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Error implements Error
|
||||||
func (le LineError) Error() string {
|
func (le LineError) Error() string {
|
||||||
return fmt.Sprintf(":%d %s", le.Line, clifmt.Color(31, le.Err.Error()))
|
return fmt.Sprintf(":%d %s", le.Line, clifmt.Color(31, le.Err.Error()))
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ErrNullContext is raised when the given context is nil
|
||||||
var ErrNullContext = errors.New("null context")
|
var ErrNullContext = errors.New("null context")
|
||||||
|
|
||||||
// Reader is the buildfile reader
|
// Reader is the buildfile reader
|
||||||
|
|
|
@ -8,7 +8,10 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ErrUnknownExtension is raised when encountering an unknown extension
|
||||||
var ErrUnknownExtension = errors.New("unknown extension format")
|
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")
|
var ErrUnknownFormat = errors.New("cannot infer format from content")
|
||||||
|
|
||||||
// Load the current file and create the configuration format accordingly
|
// Load the current file and create the configuration format accordingly
|
||||||
|
|
|
@ -7,7 +7,9 @@ import (
|
||||||
"strings"
|
"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 {
|
type config struct {
|
||||||
raw string
|
raw string
|
||||||
|
@ -63,7 +65,7 @@ func (d config) Exec(ctx ExecutionContext) ([]byte, error) {
|
||||||
|
|
||||||
// 2. try to update value
|
// 2. try to update value
|
||||||
if !format.Set(d.Path, d.Value) {
|
if !format.Set(d.Path, d.Value) {
|
||||||
return nil, ErrImpossible
|
return nil, ErrCannotSet
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Update file
|
// 3. Update file
|
||||||
|
|
|
@ -16,6 +16,7 @@ type T interface {
|
||||||
Exec(ExecutionContext) ([]byte, error)
|
Exec(ExecutionContext) ([]byte, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ExecutionContext contains system-specific drivers to manage the host
|
||||||
type ExecutionContext struct {
|
type ExecutionContext struct {
|
||||||
PackageManager pkg.PackageManager
|
PackageManager pkg.PackageManager
|
||||||
ServiceManager ser.ServiceManager
|
ServiceManager ser.ServiceManager
|
||||||
|
|
|
@ -4,5 +4,9 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ErrInvalidSyntax is raised when encountering an invalid token
|
||||||
var ErrInvalidSyntax = errors.New("invalid instruction format")
|
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")
|
var ErrUnknownInstruction = errors.New("unknown instruction")
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package pkg
|
package pkg
|
||||||
|
|
||||||
|
// DefaultManager if not empty is the default package-manager to use when missing
|
||||||
var DefaultManager = ""
|
var DefaultManager = ""
|
||||||
|
|
||||||
// PackageManager is the common interface for all package-manager drivers (e.g. `dpkg` for debian-based, `pacman` for arch)
|
// 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"
|
"errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ErrUnknownManager is raised when the asked manager does not exist
|
||||||
var ErrUnknownManager = errors.New("unknown package manager")
|
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")
|
var ErrNotInstalled = errors.New("no candidate installed")
|
||||||
|
|
||||||
|
// Load a specific package-manager by its name
|
||||||
func Load(_manager string) (PackageManager, error) {
|
func Load(_manager string) (PackageManager, error) {
|
||||||
|
|
||||||
// 1. create manager (fail if unknown)
|
// 1. create manager (fail if unknown)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package ser
|
package ser
|
||||||
|
|
||||||
|
// DefaultManager if not empty is the default service-manager to use when missing
|
||||||
var DefaultManager = "systemd"
|
var DefaultManager = "systemd"
|
||||||
|
|
||||||
// ServiceManager is the common interface for service managers (systemd, init.d)
|
// ServiceManager is the common interface for service managers (systemd, init.d)
|
||||||
|
|
|
@ -4,4 +4,5 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ErrUnknownAction is raised when an unknown action is called (enable, start, ...)
|
||||||
var ErrUnknownAction = errors.New("unknown action")
|
var ErrUnknownAction = errors.New("unknown action")
|
||||||
|
|
|
@ -4,16 +4,22 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ErrUnknownManager is raised when the asked manager does not exist
|
||||||
var ErrUnknownManager = errors.New("unknown service manager")
|
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) {
|
func Load(_manager string) (ServiceManager, error) {
|
||||||
|
|
||||||
// 1. create manager (fail if unknown)
|
// 1. create manager (fail if unknown)
|
||||||
var manager ServiceManager
|
var manager ServiceManager
|
||||||
switch _manager {
|
switch _manager {
|
||||||
case "systemd":
|
case "systemd":
|
||||||
manager = new(Systemd)
|
manager = new(systemd)
|
||||||
default:
|
default:
|
||||||
return nil, ErrUnknownManager
|
return nil, ErrUnknownManager
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,14 +4,14 @@ import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Systemd struct{}
|
type systemd struct{}
|
||||||
|
|
||||||
// available actions
|
// available actions
|
||||||
var actions = []string{"enable", "disable", "start", "stop", "reload", "restart"}
|
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
|
// 1. fail if unknown action
|
||||||
known := false
|
known := false
|
||||||
|
|
Loading…
Reference in New Issue