From 536556b6fa3165a3ab965714d3d850d4ac60b6c1 Mon Sep 17 00:00:00 2001 From: Sven Greb Date: Thu, 22 Apr 2021 21:05:37 +0200 Subject: [PATCH] Remove unnecessary `Wand` parameter in `Task` creation functions (#77) Before most `Task` creation functions [^1] [^2] [^3] [^4] required a `Wand` as parameter which was not used but blocked the internal usage for task runners. Therefore these parameters have been removed. When necessary, it can be added individually later on or can be reintroduced through a dedicated function with extended parameters to cover different use cases. [^1]: https://pkg.go.dev/github.com/svengreb/wand@v0.5.0/pkg/task/gofumpt#New [^2]: https://pkg.go.dev/github.com/svengreb/wand@v0.5.0/pkg/task/goimports#New [^3]: https://pkg.go.dev/github.com/svengreb/wand@v0.5.0/pkg/task/golang/build#New [^4]: https://pkg.go.dev/github.com/svengreb/wand@v0.5.0/pkg/task/golang/install#New Closes GH-76 --- examples/custom_task/tasks.go | 3 +-- pkg/elder/elder.go | 12 ++++++------ pkg/task/gofumpt/gofumpt.go | 3 +-- pkg/task/goimports/goimports.go | 3 +-- pkg/task/golang/build/build.go | 3 +-- pkg/task/golang/install/install.go | 3 +-- pkg/task/golang/test/test.go | 3 +-- pkg/task/golangcilint/golangcilint.go | 3 +-- pkg/task/gox/gox.go | 3 +-- 9 files changed, 14 insertions(+), 22 deletions(-) diff --git a/examples/custom_task/tasks.go b/examples/custom_task/tasks.go index ec1802b..db5cfa8 100644 --- a/examples/custom_task/tasks.go +++ b/examples/custom_task/tasks.go @@ -3,7 +3,6 @@ package main import ( - "github.com/svengreb/wand" "github.com/svengreb/wand/pkg/app" "github.com/svengreb/wand/pkg/task" ) @@ -66,7 +65,7 @@ func (t *MixTask) Options() task.Options { } // NewMixTask creates a new mix task for the fruit CLI. -func NewMixTask(wand wand.Wand, ac app.Config, opts ...MixOption) (*MixTask, error) { +func NewMixTask(ac app.Config, opts ...MixOption) (*MixTask, error) { return &MixTask{ac: ac, opts: NewMixOptions(opts...)}, nil } diff --git a/pkg/elder/elder.go b/pkg/elder/elder.go index aca1907..1c45b69 100644 --- a/pkg/elder/elder.go +++ b/pkg/elder/elder.go @@ -130,7 +130,7 @@ func (e *Elder) GoBuild(appName string, opts ...taskGoBuild.Option) error { return fmt.Errorf("get %q application configuration: %w", appName, acErr) } - return e.goRunner.Run(taskGoBuild.New(e, ac, opts...)) + return e.goRunner.Run(taskGoBuild.New(ac, opts...)) } // Gofumpt is a task for the "mvdan.cc/gofumpt" Go module command. @@ -149,7 +149,7 @@ func (e *Elder) Gofumpt(appName string, opts ...taskGofumpt.Option) error { return fmt.Errorf("get %q application configuration: %w", appName, acErr) } - return e.gobinRunner.Run(taskGofumpt.New(e, ac, opts...)) + return e.gobinRunner.Run(taskGofumpt.New(ac, opts...)) } // Goimports is a task for the "golang.org/x/tools/cmd/goimports" Go module command. @@ -166,7 +166,7 @@ func (e *Elder) Goimports(appName string, opts ...taskGoimports.Option) error { return fmt.Errorf("get %q application configuration: %w", appName, acErr) } - t, tErr := taskGoimports.New(e, ac, opts...) + t, tErr := taskGoimports.New(ac, opts...) if tErr != nil { return fmt.Errorf("create %q task: %w", taskGoimports.TaskName, tErr) } @@ -191,7 +191,7 @@ func (e *Elder) GolangCILint(appName string, opts ...taskGolangCILint.Option) er return fmt.Errorf("get %q application configuration: %w", appName, acErr) } - t, tErr := taskGolangCILint.New(e, ac, opts...) + t, tErr := taskGolangCILint.New(ac, opts...) if tErr != nil { return fmt.Errorf("create %q task: %w", taskGolangCILint.TaskName, tErr) } @@ -211,7 +211,7 @@ func (e *Elder) GoTest(appName string, opts ...taskGoTest.Option) error { return fmt.Errorf("get %q application configuration: %w", appName, acErr) } - t := taskGoTest.New(e, ac, opts...) + t := taskGoTest.New(ac, opts...) tOpts, ok := t.Options().(taskGoTest.Options) if !ok { return fmt.Errorf(`convert task options to "%T"`, taskGoTest.Options{}) @@ -239,7 +239,7 @@ func (e *Elder) Gox(appName string, opts ...taskGox.Option) error { return fmt.Errorf("get %q application configuration: %w", appName, acErr) } - t, tErr := taskGox.New(e, ac, opts...) + t, tErr := taskGox.New(ac, opts...) if tErr != nil { return fmt.Errorf("create %q task: %w", taskGox.TaskName, tErr) } diff --git a/pkg/task/gofumpt/gofumpt.go b/pkg/task/gofumpt/gofumpt.go index 08000f0..84327a7 100644 --- a/pkg/task/gofumpt/gofumpt.go +++ b/pkg/task/gofumpt/gofumpt.go @@ -12,7 +12,6 @@ package gofumpt import ( - "github.com/svengreb/wand" "github.com/svengreb/wand/pkg/app" "github.com/svengreb/wand/pkg/project" "github.com/svengreb/wand/pkg/task" @@ -95,6 +94,6 @@ func (t *Task) Options() task.Options { // New creates a new task for the "mvdan.cc/gofumpt" Go module command. //nolint:gocritic // The app.Config struct is passed as value by design to ensure immutability. -func New(wand wand.Wand, ac app.Config, opts ...Option) *Task { +func New(ac app.Config, opts ...Option) *Task { return &Task{ac: ac, opts: NewOptions(opts...)} } diff --git a/pkg/task/goimports/goimports.go b/pkg/task/goimports/goimports.go index 21d6680..7141229 100644 --- a/pkg/task/goimports/goimports.go +++ b/pkg/task/goimports/goimports.go @@ -13,7 +13,6 @@ import ( "fmt" "strings" - "github.com/svengreb/wand" "github.com/svengreb/wand/pkg/app" "github.com/svengreb/wand/pkg/project" "github.com/svengreb/wand/pkg/task" @@ -95,7 +94,7 @@ func (t *Task) Options() task.Options { // New creates a new task for the "golang.org/x/tools/cmd/goimports" Go module command. //nolint:gocritic // The app.Config struct is passed as value by design to ensure immutability. -func New(wand wand.Wand, ac app.Config, opts ...Option) (*Task, error) { +func New(ac app.Config, opts ...Option) (*Task, error) { opt, optErr := NewOptions(opts...) if optErr != nil { return nil, optErr diff --git a/pkg/task/golang/build/build.go b/pkg/task/golang/build/build.go index 5d58287..19204ea 100644 --- a/pkg/task/golang/build/build.go +++ b/pkg/task/golang/build/build.go @@ -7,7 +7,6 @@ package build import ( "path/filepath" - "github.com/svengreb/wand" "github.com/svengreb/wand/pkg/app" "github.com/svengreb/wand/pkg/task" taskGo "github.com/svengreb/wand/pkg/task/golang" @@ -61,7 +60,7 @@ func (t *Task) Options() task.Options { // New creates a new task for the Go toolchain "build" command. //nolint:gocritic // The app.Config struct is passed as value by design to ensure immutability. -func New(wand wand.Wand, ac app.Config, opts ...Option) *Task { +func New(ac app.Config, opts ...Option) *Task { opt := NewOptions(opts...) if opt.BinaryArtifactName == "" { diff --git a/pkg/task/golang/install/install.go b/pkg/task/golang/install/install.go index 2c8b007..34fe10f 100644 --- a/pkg/task/golang/install/install.go +++ b/pkg/task/golang/install/install.go @@ -14,7 +14,6 @@ package install import ( - "github.com/svengreb/wand" "github.com/svengreb/wand/pkg/app" "github.com/svengreb/wand/pkg/task" ) @@ -65,7 +64,7 @@ func (t *Task) Options() task.Options { // New creates a new task for the Go toolchain "install" command. //nolint:gocritic // The app.Config struct is passed as value by design to ensure immutability. -func New(wand wand.Wand, ac app.Config, opts ...Option) (*Task, error) { +func New(ac app.Config, opts ...Option) (*Task, error) { opt, optErr := NewOptions(opts...) if optErr != nil { return nil, optErr diff --git a/pkg/task/golang/test/test.go b/pkg/task/golang/test/test.go index e0687ee..843e197 100644 --- a/pkg/task/golang/test/test.go +++ b/pkg/task/golang/test/test.go @@ -8,7 +8,6 @@ import ( "fmt" "path/filepath" - "github.com/svengreb/wand" "github.com/svengreb/wand/pkg/app" "github.com/svengreb/wand/pkg/task" taskGo "github.com/svengreb/wand/pkg/task/golang" @@ -116,7 +115,7 @@ func (t *Task) Options() task.Options { // New creates a new task for the Go toolchain "test" command. //nolint:gocritic // The app.Config struct is passed as value by design to ensure immutability. -func New(wand wand.Wand, ac app.Config, opts ...Option) *Task { +func New(ac app.Config, opts ...Option) *Task { opt := NewOptions(opts...) // Store test profiles and reports within the application specific subdirectory. diff --git a/pkg/task/golangcilint/golangcilint.go b/pkg/task/golangcilint/golangcilint.go index bf720de..eed9fc1 100644 --- a/pkg/task/golangcilint/golangcilint.go +++ b/pkg/task/golangcilint/golangcilint.go @@ -11,7 +11,6 @@ package golangcilint import ( - "github.com/svengreb/wand" "github.com/svengreb/wand/pkg/app" "github.com/svengreb/wand/pkg/project" "github.com/svengreb/wand/pkg/task" @@ -51,7 +50,7 @@ func (t *Task) Options() task.Options { // New creates a new task for the "github.com/golangci/golangci-lint/cmd/golangci-lint" Go module command. // If no extra arguments are configured, DefaultArgs are passed to the command. //nolint:gocritic // The app.Config struct is passed as value by design to ensure immutability. -func New(wand wand.Wand, ac app.Config, opts ...Option) (*Task, error) { +func New(ac app.Config, opts ...Option) (*Task, error) { opt, optErr := NewOptions(opts...) if optErr != nil { return nil, optErr diff --git a/pkg/task/gox/gox.go b/pkg/task/gox/gox.go index dd65dac..1e47933 100644 --- a/pkg/task/gox/gox.go +++ b/pkg/task/gox/gox.go @@ -13,7 +13,6 @@ import ( "fmt" "strings" - "github.com/svengreb/wand" "github.com/svengreb/wand/pkg/app" "github.com/svengreb/wand/pkg/project" "github.com/svengreb/wand/pkg/task" @@ -89,7 +88,7 @@ func (t *Task) Options() task.Options { // New creates a new task for the "github.com/mitchellh/gox" Go module command. //nolint:gocritic // The app.Config struct is passed as value by design to ensure immutability. -func New(wand wand.Wand, ac app.Config, opts ...Option) (*Task, error) { +func New(ac app.Config, opts ...Option) (*Task, error) { opt, optErr := NewOptions(opts...) if optErr != nil { return nil, optErr