1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/pipeline/defaults/defaults.go
Carlos Alexandro Becker 1ed299a6d7 refactor: defaulter interface
Right now the code looks weird because the defaults
of a pipe are far away of the implementation of the pipe.

the intend of this PR is to bring them closer by having a
Defaulter interface.

I also renamed the Pipe interface to Piper, and removed
the Description method in favor for fmt.Stringer.
2017-12-03 13:00:01 -02:00

55 lines
1.4 KiB
Go

// Package defaults implements the Pipe interface providing default values
// for missing configuration.
package defaults
import (
"github.com/apex/log"
"github.com/goreleaser/goreleaser/context"
"github.com/goreleaser/goreleaser/pipeline"
"github.com/goreleaser/goreleaser/pipeline/archive"
"github.com/goreleaser/goreleaser/pipeline/brew"
"github.com/goreleaser/goreleaser/pipeline/build"
"github.com/goreleaser/goreleaser/pipeline/checksums"
"github.com/goreleaser/goreleaser/pipeline/docker"
"github.com/goreleaser/goreleaser/pipeline/fpm"
"github.com/goreleaser/goreleaser/pipeline/release"
"github.com/goreleaser/goreleaser/pipeline/snapshot"
)
// Pipe for brew deployment
type Pipe struct{}
// Description of the pipe
func (Pipe) String() string {
return "setting defaults for:"
}
var defaulters = []pipeline.Defaulter{
snapshot.Pipe{},
release.Pipe{},
archive.Pipe{},
build.Pipe{},
fpm.Pipe{},
checksums.Pipe{},
docker.Pipe{},
brew.Pipe{},
}
// Run the pipe
func (Pipe) Run(ctx *context.Context) error {
if ctx.Config.Dist == "" {
ctx.Config.Dist = "dist"
}
for _, defaulter := range defaulters {
log.Infof("\t%s", defaulter.String())
if err := defaulter.Default(ctx); err != nil {
return err
}
}
if ctx.Config.ProjectName == "" {
ctx.Config.ProjectName = ctx.Config.Release.GitHub.Name
}
log.WithField("config", ctx.Config).Debug("defaults set")
return nil
}