From 235e30aeb7e92ee18a1d154123e3de92a14dfe2a Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sun, 11 Nov 2018 19:01:00 +0100 Subject: [PATCH] unexport ser/systemd | fixes (golint) --- args.go | 3 +++ internal/buildfile/errors.go | 2 ++ internal/buildfile/reader.go | 1 + internal/cnf/loader.go | 3 +++ internal/instruction/cnf.go | 6 ++++-- internal/instruction/common.go | 1 + internal/instruction/errors.go | 4 ++++ internal/pkg/common.go | 1 + internal/pkg/loader.go | 6 ++++++ internal/ser/common.go | 1 + internal/ser/errors.go | 1 + internal/ser/loader.go | 10 ++++++++-- internal/ser/systemd.go | 6 +++--- 13 files changed, 38 insertions(+), 7 deletions(-) diff --git a/args.go b/args.go index 96867e0..4b3b79b 100644 --- a/args.go +++ b/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) diff --git a/internal/buildfile/errors.go b/internal/buildfile/errors.go index 92eaa70..1e54941 100644 --- a/internal/buildfile/errors.go +++ b/internal/buildfile/errors.go @@ -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())) } diff --git a/internal/buildfile/reader.go b/internal/buildfile/reader.go index 5d3fba3..510f36a 100644 --- a/internal/buildfile/reader.go +++ b/internal/buildfile/reader.go @@ -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 diff --git a/internal/cnf/loader.go b/internal/cnf/loader.go index 808017f..18ecb25 100644 --- a/internal/cnf/loader.go +++ b/internal/cnf/loader.go @@ -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 diff --git a/internal/instruction/cnf.go b/internal/instruction/cnf.go index c8069ea..b006c5f 100644 --- a/internal/instruction/cnf.go +++ b/internal/instruction/cnf.go @@ -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 diff --git a/internal/instruction/common.go b/internal/instruction/common.go index 486c47c..f0b6ccc 100644 --- a/internal/instruction/common.go +++ b/internal/instruction/common.go @@ -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 diff --git a/internal/instruction/errors.go b/internal/instruction/errors.go index 64eaf45..0eeb111 100644 --- a/internal/instruction/errors.go +++ b/internal/instruction/errors.go @@ -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") diff --git a/internal/pkg/common.go b/internal/pkg/common.go index 00c86be..54c6b27 100644 --- a/internal/pkg/common.go +++ b/internal/pkg/common.go @@ -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) diff --git a/internal/pkg/loader.go b/internal/pkg/loader.go index 7b0c01f..63e8b26 100644 --- a/internal/pkg/loader.go +++ b/internal/pkg/loader.go @@ -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) diff --git a/internal/ser/common.go b/internal/ser/common.go index dfe1e72..5def149 100644 --- a/internal/ser/common.go +++ b/internal/ser/common.go @@ -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) diff --git a/internal/ser/errors.go b/internal/ser/errors.go index ebd6cf8..037726b 100644 --- a/internal/ser/errors.go +++ b/internal/ser/errors.go @@ -4,4 +4,5 @@ import ( "errors" ) +// ErrUnknownAction is raised when an unknown action is called (enable, start, ...) var ErrUnknownAction = errors.New("unknown action") diff --git a/internal/ser/loader.go b/internal/ser/loader.go index 31636bb..99a15d7 100644 --- a/internal/ser/loader.go +++ b/internal/ser/loader.go @@ -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 } diff --git a/internal/ser/systemd.go b/internal/ser/systemd.go index 0b9e8ed..c20ab04 100644 --- a/internal/ser/systemd.go +++ b/internal/ser/systemd.go @@ -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