2018-02-17 17:43:29 +02:00
|
|
|
// Package deprecate provides simple functions to standardize the output
|
|
|
|
// of deprecation notices on goreleaser
|
|
|
|
package deprecate
|
|
|
|
|
|
|
|
import (
|
2021-03-01 19:18:57 +02:00
|
|
|
"bytes"
|
2018-02-17 17:43:29 +02:00
|
|
|
"strings"
|
2021-03-01 19:18:57 +02:00
|
|
|
"text/template"
|
2018-02-17 17:43:29 +02:00
|
|
|
|
2022-06-22 02:11:15 +02:00
|
|
|
"github.com/caarlos0/log"
|
2024-05-26 20:02:57 +02:00
|
|
|
"github.com/goreleaser/goreleaser/v2/internal/logext"
|
|
|
|
"github.com/goreleaser/goreleaser/v2/pkg/context"
|
2018-02-17 17:43:29 +02:00
|
|
|
)
|
|
|
|
|
2018-05-01 05:58:10 +02:00
|
|
|
const baseURL = "https://goreleaser.com/deprecations#"
|
2018-02-17 17:43:29 +02:00
|
|
|
|
2020-05-26 05:48:10 +02:00
|
|
|
// Notice warns the user about the deprecation of the given property.
|
2020-04-12 19:31:35 +02:00
|
|
|
func Notice(ctx *context.Context, property string) {
|
2023-07-25 13:26:44 +02:00
|
|
|
NoticeCustom(ctx, property, "{{ .Property }} should not be used anymore, check {{ .URL }} for more info")
|
2021-03-01 19:18:57 +02:00
|
|
|
}
|
|
|
|
|
2024-04-17 01:56:45 +02:00
|
|
|
var urlPropertyReplacer = strings.NewReplacer(
|
|
|
|
".", "",
|
|
|
|
"_", "",
|
|
|
|
":", "",
|
|
|
|
" ", "-",
|
|
|
|
)
|
|
|
|
|
2021-05-25 21:49:49 +02:00
|
|
|
// NoticeCustom warns the user about the deprecation of the given property.
|
2021-03-01 19:18:57 +02:00
|
|
|
func NoticeCustom(ctx *context.Context, property, tmpl string) {
|
2018-05-01 05:58:10 +02:00
|
|
|
// replaces . and _ with -
|
2024-04-17 01:56:45 +02:00
|
|
|
url := baseURL + urlPropertyReplacer.Replace(property)
|
2021-03-01 19:18:57 +02:00
|
|
|
var out bytes.Buffer
|
2023-01-29 05:24:11 +02:00
|
|
|
if err := template.
|
|
|
|
Must(template.New("deprecation").Parse("DEPRECATED: "+tmpl)).
|
|
|
|
Execute(&out, templateData{
|
2023-07-25 13:26:44 +02:00
|
|
|
URL: logext.URL(url),
|
|
|
|
Property: logext.Keyword(property),
|
2023-01-29 05:24:11 +02:00
|
|
|
}); err != nil {
|
2021-03-01 19:18:57 +02:00
|
|
|
panic(err) // this should never happen
|
|
|
|
}
|
2022-06-22 02:11:15 +02:00
|
|
|
|
|
|
|
ctx.Deprecated = true
|
2023-07-25 13:26:44 +02:00
|
|
|
log.Warn(logext.Warning(out.String()))
|
2021-03-01 19:18:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type templateData struct {
|
|
|
|
URL string
|
|
|
|
Property string
|
2018-02-17 17:43:29 +02:00
|
|
|
}
|