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