1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-08 03:31:59 +02:00
goreleaser/internal/deprecate/deprecate.go

51 lines
1.3 KiB
Go
Raw Normal View History

// Package deprecate provides simple functions to standardize the output
// of deprecation notices on goreleaser
package deprecate
import (
"bytes"
"strings"
"text/template"
"github.com/caarlos0/log"
"github.com/goreleaser/goreleaser/v2/internal/logext"
"github.com/goreleaser/goreleaser/v2/pkg/context"
)
2018-05-01 05:58:10 +02:00
const baseURL = "https://goreleaser.com/deprecations#"
// Notice warns the user about the deprecation of the given property.
func Notice(ctx *context.Context, property string) {
NoticeCustom(ctx, property, "{{ .Property }} should not be used anymore, check {{ .URL }} for more info")
}
var urlPropertyReplacer = strings.NewReplacer(
".", "",
"_", "",
":", "",
" ", "-",
)
// NoticeCustom warns the user about the deprecation of the given property.
func NoticeCustom(ctx *context.Context, property, tmpl string) {
2018-05-01 05:58:10 +02:00
// replaces . and _ with -
url := baseURL + urlPropertyReplacer.Replace(property)
var out bytes.Buffer
if err := template.
Must(template.New("deprecation").Parse("DEPRECATED: "+tmpl)).
Execute(&out, templateData{
URL: logext.URL(url),
Property: logext.Keyword(property),
}); err != nil {
panic(err) // this should never happen
}
ctx.Deprecated = true
log.Warn(logext.Warning(out.String()))
}
type templateData struct {
URL string
Property string
}