github.com/ahmet2mir/goreleaser@v0.180.3-0.20210927151101-8e5ee5a9b8c5/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/apex/log" 11 "github.com/apex/log/handlers/cli" 12 "github.com/fatih/color" 13 "github.com/goreleaser/goreleaser/pkg/context" 14 ) 15 16 const baseURL = "https://goreleaser.com/deprecations#" 17 18 // Notice warns the user about the deprecation of the given property. 19 func Notice(ctx *context.Context, property string) { 20 NoticeCustom(ctx, property, "`{{ .Property }}` should not be used anymore, check {{ .URL }} for more info") 21 } 22 23 // NoticeCustom warns the user about the deprecation of the given property. 24 func NoticeCustom(ctx *context.Context, property, tmpl string) { 25 ctx.Deprecated = true 26 cli.Default.Padding += 3 27 defer func() { 28 cli.Default.Padding -= 3 29 }() 30 // replaces . and _ with - 31 url := baseURL + strings.NewReplacer( 32 ".", "", 33 "_", "", 34 ).Replace(property) 35 var out bytes.Buffer 36 if err := template.Must(template.New("deprecation").Parse("DEPRECATED: "+tmpl)).Execute(&out, templateData{ 37 URL: url, 38 Property: property, 39 }); err != nil { 40 panic(err) // this should never happen 41 } 42 log.Warn(color.New(color.Bold, color.FgHiYellow).Sprintf(out.String())) 43 } 44 45 type templateData struct { 46 URL string 47 Property string 48 }