github.com/szyn/goreleaser@v0.76.1-0.20180517112710-333da09a1297/pipeline/defaults/defaults.go (about)

     1  // Package defaults implements the Pipe interface providing default values
     2  // for missing configuration.
     3  package defaults
     4  
     5  import (
     6  	"fmt"
     7  
     8  	"github.com/apex/log"
     9  	"github.com/goreleaser/goreleaser/context"
    10  	"github.com/goreleaser/goreleaser/pipeline/archive"
    11  	"github.com/goreleaser/goreleaser/pipeline/artifactory"
    12  	"github.com/goreleaser/goreleaser/pipeline/brew"
    13  	"github.com/goreleaser/goreleaser/pipeline/build"
    14  	"github.com/goreleaser/goreleaser/pipeline/checksums"
    15  	"github.com/goreleaser/goreleaser/pipeline/docker"
    16  	"github.com/goreleaser/goreleaser/pipeline/env"
    17  	"github.com/goreleaser/goreleaser/pipeline/fpm"
    18  	"github.com/goreleaser/goreleaser/pipeline/nfpm"
    19  	"github.com/goreleaser/goreleaser/pipeline/project"
    20  	"github.com/goreleaser/goreleaser/pipeline/release"
    21  	"github.com/goreleaser/goreleaser/pipeline/s3"
    22  	"github.com/goreleaser/goreleaser/pipeline/scoop"
    23  	"github.com/goreleaser/goreleaser/pipeline/sign"
    24  	"github.com/goreleaser/goreleaser/pipeline/snapcraft"
    25  	"github.com/goreleaser/goreleaser/pipeline/snapshot"
    26  )
    27  
    28  // Pipe that sets the defaults
    29  type Pipe struct{}
    30  
    31  func (Pipe) String() string {
    32  	return "setting defaults for:"
    33  }
    34  
    35  // Defaulter can be implemented by a Piper to set default values for its
    36  // configuration.
    37  type Defaulter interface {
    38  	fmt.Stringer
    39  
    40  	// Default sets the configuration defaults
    41  	Default(ctx *context.Context) error
    42  }
    43  
    44  var defaulters = []Defaulter{
    45  	env.Pipe{},
    46  	snapshot.Pipe{},
    47  	release.Pipe{},
    48  	project.Pipe{},
    49  	archive.Pipe{},
    50  	build.Pipe{},
    51  	fpm.Pipe{},
    52  	nfpm.Pipe{},
    53  	snapcraft.Pipe{},
    54  	checksums.Pipe{},
    55  	sign.Pipe{},
    56  	docker.Pipe{},
    57  	artifactory.Pipe{},
    58  	s3.Pipe{},
    59  	brew.Pipe{},
    60  	scoop.Pipe{},
    61  }
    62  
    63  // Run the pipe
    64  func (Pipe) Run(ctx *context.Context) error {
    65  	if ctx.Config.Dist == "" {
    66  		ctx.Config.Dist = "dist"
    67  	}
    68  	if ctx.Config.GitHubURLs.Download == "" {
    69  		ctx.Config.GitHubURLs.Download = "https://github.com"
    70  	}
    71  	for _, defaulter := range defaulters {
    72  		log.Info(defaulter.String())
    73  		if err := defaulter.Default(ctx); err != nil {
    74  			return err
    75  		}
    76  	}
    77  	return nil
    78  }