Skip to content

Commit

Permalink
Remove unnecessary Wand parameter in Task creation functions (#77)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
svengreb authored Apr 22, 2021
1 parent 50d743b commit 536556b
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 22 deletions.
3 changes: 1 addition & 2 deletions examples/custom_task/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
package main

import (
"github.com/svengreb/wand"
"github.com/svengreb/wand/pkg/app"
"github.com/svengreb/wand/pkg/task"
)
Expand Down Expand Up @@ -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
}

Expand Down
12 changes: 6 additions & 6 deletions pkg/elder/elder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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{})
Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/task/gofumpt/gofumpt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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...)}
}
3 changes: 1 addition & 2 deletions pkg/task/goimports/goimports.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions pkg/task/golang/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 == "" {
Expand Down
3 changes: 1 addition & 2 deletions pkg/task/golang/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package install

import (
"github.com/svengreb/wand"
"github.com/svengreb/wand/pkg/app"
"github.com/svengreb/wand/pkg/task"
)
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions pkg/task/golang/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions pkg/task/golangcilint/golangcilint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions pkg/task/gox/gox.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 536556b

Please sign in to comment.