mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-08 03:31:59 +02:00
3df29b67ab
* feat: deprecate gofish gofish was deprecated by its authors, this deprecates it here too refs https://github.com/goreleaser/goreleaser/discussions/2998 Signed-off-by: Carlos A Becker <caarlos0@gmail.com> * fix: do not publish rig anymore Signed-off-by: Carlos A Becker <caarlos0@gmail.com> * docs: remove install * chore: deprecate * fix(gofish): fix broke logs Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
80 lines
2.0 KiB
Go
80 lines
2.0 KiB
Go
// Package deprecate provides simple functions to standardize the output
|
|
// of deprecation notices on goreleaser
|
|
package deprecate
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
"strings"
|
|
"sync"
|
|
"text/template"
|
|
|
|
"github.com/apex/log"
|
|
"github.com/apex/log/handlers/cli"
|
|
"github.com/fatih/color"
|
|
"github.com/goreleaser/goreleaser/pkg/context"
|
|
)
|
|
|
|
const baseURL = "https://goreleaser.com/deprecations#"
|
|
|
|
// NewWriter return a io.Writer that notices deprecations.
|
|
func NewWriter(ctx *context.Context) io.Writer {
|
|
return &writer{ctx: ctx}
|
|
}
|
|
|
|
type writer struct {
|
|
ctx *context.Context
|
|
once sync.Once
|
|
}
|
|
|
|
func (w *writer) Write(p []byte) (n int, err error) {
|
|
w.once.Do(func() {
|
|
w.ctx.Deprecated = true
|
|
})
|
|
log.Warn(color.New(color.Bold, color.FgHiYellow).Sprintf("DEPRECATED: " + strings.TrimSuffix(string(p), "\n")))
|
|
return len(p), nil
|
|
}
|
|
|
|
// 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")
|
|
}
|
|
|
|
// NoticeCustom warns the user about the deprecation of the given property.
|
|
func NoticeCustom(ctx *context.Context, property, tmpl string) {
|
|
ctx.Deprecated = true
|
|
// XXX: this is very ugly!
|
|
oldHandler, ok := log.Log.(*log.Logger).Handler.(*cli.Handler)
|
|
if !ok {
|
|
// probably in a test, and the cli logger wasn't set
|
|
return
|
|
}
|
|
w := oldHandler.Writer
|
|
handler := cli.New(w)
|
|
handler.Padding = cli.Default.Padding + 3
|
|
log := &log.Logger{
|
|
Handler: handler,
|
|
Level: log.InfoLevel,
|
|
}
|
|
// replaces . and _ with -
|
|
url := baseURL + strings.NewReplacer(
|
|
".", "",
|
|
"_", "",
|
|
":", "",
|
|
" ", "-",
|
|
).Replace(property)
|
|
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
|
|
}
|
|
log.Warn(color.New(color.Bold, color.FgHiYellow).Sprintf(out.String()))
|
|
}
|
|
|
|
type templateData struct {
|
|
URL string
|
|
Property string
|
|
}
|