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