github.com/triarius/goreleaser@v1.12.5/internal/deprecate/deprecate.go (about) 1 // Package deprecate provides simple functions to standardize the output 2 // of deprecation notices on goreleaser 3 package deprecate 4 5 import ( 6 "bytes" 7 "strings" 8 "text/template" 9 10 "github.com/caarlos0/log" 11 "github.com/charmbracelet/lipgloss" 12 "github.com/triarius/goreleaser/pkg/context" 13 ) 14 15 const baseURL = "https://goreleaser.com/deprecations#" 16 17 var warnStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("11")).Bold(true) 18 19 // Notice warns the user about the deprecation of the given property. 20 func Notice(ctx *context.Context, property string) { 21 NoticeCustom(ctx, property, "`{{ .Property }}` should not be used anymore, check {{ .URL }} for more info") 22 } 23 24 // NoticeCustom warns the user about the deprecation of the given property. 25 func NoticeCustom(ctx *context.Context, property, tmpl string) { 26 log.IncreasePadding() 27 defer log.DecreasePadding() 28 29 // replaces . and _ with - 30 url := baseURL + strings.NewReplacer( 31 ".", "", 32 "_", "", 33 ":", "", 34 " ", "-", 35 ).Replace(property) 36 var out bytes.Buffer 37 if err := template.Must(template.New("deprecation").Parse("DEPRECATED: "+tmpl)).Execute(&out, templateData{ 38 URL: url, 39 Property: property, 40 }); err != nil { 41 panic(err) // this should never happen 42 } 43 44 ctx.Deprecated = true 45 log.Warn(warnStyle.Render(out.String())) 46 } 47 48 type templateData struct { 49 URL string 50 Property string 51 }