2017-04-14 15:39:32 -03:00
|
|
|
// Package defaults implements the Pipe interface providing default values
|
|
|
|
// for missing configuration.
|
2017-01-14 12:34:22 -02:00
|
|
|
package defaults
|
|
|
|
|
|
|
|
import (
|
2021-09-09 03:42:13 +02:00
|
|
|
"fmt"
|
2020-11-21 14:36:29 +01:00
|
|
|
"strings"
|
|
|
|
|
2020-07-06 14:48:17 +01:00
|
|
|
"github.com/goreleaser/goreleaser/internal/client"
|
2021-09-18 10:21:29 -03:00
|
|
|
"github.com/goreleaser/goreleaser/internal/middleware/errhandler"
|
2021-09-09 03:42:13 +02:00
|
|
|
"github.com/goreleaser/goreleaser/internal/tmpl"
|
2018-08-14 23:50:20 -03:00
|
|
|
"github.com/goreleaser/goreleaser/pkg/context"
|
2018-10-26 11:03:55 -03:00
|
|
|
"github.com/goreleaser/goreleaser/pkg/defaults"
|
2017-01-14 12:34:22 -02:00
|
|
|
)
|
|
|
|
|
2020-05-26 00:48:10 -03:00
|
|
|
// Pipe that sets the defaults.
|
2017-01-14 12:34:22 -02:00
|
|
|
type Pipe struct{}
|
|
|
|
|
2021-09-18 10:21:29 -03:00
|
|
|
func (Pipe) String() string { return "setting defaults" }
|
2017-12-02 19:53:19 -02:00
|
|
|
|
2020-05-26 00:48:10 -03:00
|
|
|
// Run the pipe.
|
2017-12-02 19:53:19 -02:00
|
|
|
func (Pipe) Run(ctx *context.Context) error {
|
2017-11-26 21:25:51 -02:00
|
|
|
if ctx.Config.Dist == "" {
|
|
|
|
ctx.Config.Dist = "dist"
|
|
|
|
}
|
2018-03-08 17:16:49 -03:00
|
|
|
if ctx.Config.GitHubURLs.Download == "" {
|
2020-07-06 14:48:17 +01:00
|
|
|
ctx.Config.GitHubURLs.Download = client.DefaultGitHubDownloadURL
|
2018-03-08 17:16:49 -03:00
|
|
|
}
|
2019-06-29 16:02:40 +02:00
|
|
|
if ctx.Config.GitLabURLs.Download == "" {
|
2020-07-06 14:48:17 +01:00
|
|
|
ctx.Config.GitLabURLs.Download = client.DefaultGitLabDownloadURL
|
2019-06-29 16:02:40 +02:00
|
|
|
}
|
2020-11-21 14:36:29 +01:00
|
|
|
if ctx.Config.GiteaURLs.Download == "" {
|
2021-09-09 03:42:13 +02:00
|
|
|
apiURL, err := tmpl.New(ctx).Apply(ctx.Config.GiteaURLs.API)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("templating Gitea API URL: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.Config.GiteaURLs.Download = strings.ReplaceAll(apiURL, "/api/v1", "")
|
2020-11-21 14:36:29 +01:00
|
|
|
}
|
2018-10-26 11:03:55 -03:00
|
|
|
for _, defaulter := range defaults.Defaulters {
|
2022-01-06 15:32:55 -03:00
|
|
|
if err := errhandler.Handle(defaulter.Default)(ctx); err != nil {
|
2017-12-02 19:53:19 -02:00
|
|
|
return err
|
|
|
|
}
|
2017-05-01 09:59:18 -03:00
|
|
|
}
|
2017-01-14 19:41:32 +01:00
|
|
|
return nil
|
2017-01-14 12:34:22 -02:00
|
|
|
}
|