1
1
Fork 0
mirror of https://github.com/goreleaser/nfpm synced 2024-04-16 04:53:55 +02:00

feat: add deprecation notice interface (#399)

* feat: add deprecation notice interface

* fix: use a simple writer

* fix: use println
This commit is contained in:
Carlos Alexandro Becker 2021-11-12 23:07:18 -03:00 committed by GitHub
parent 5e665bdaf4
commit 2a86957187
Signed by: GitHub
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 3 deletions

View File

@ -19,6 +19,7 @@ import (
"github.com/blakesmith/ar"
"github.com/goreleaser/chglog"
"github.com/goreleaser/nfpm/v2"
"github.com/goreleaser/nfpm/v2/deprecation"
"github.com/goreleaser/nfpm/v2/files"
"github.com/goreleaser/nfpm/v2/internal/sign"
"github.com/ulikunitz/xz"
@ -170,7 +171,7 @@ func (*Deb) SetPackagerDefaults(info *nfpm.Info) {
// if in the long run we should be more strict about this and error when
// not set?
if info.Maintainer == "" {
fmt.Fprintf(os.Stderr, "DEPRECATION WARNING: Leaving the 'maintainer' field unset will not be allowed in a future version")
deprecation.Println("Leaving the 'maintainer' field unset will not be allowed in a future version")
info.Maintainer = "Unset Maintainer <unset@localhost>"
}
}

View File

@ -0,0 +1,31 @@
// Package deprecation provides centralized deprecation notice messaging for nfpm.
package deprecation
import (
"fmt"
"io"
"os"
)
type prefixed struct{ io.Writer }
func (p prefixed) Write(b []byte) (int, error) {
return p.Writer.Write(append([]byte("DEPRECATION WARNING: "), b...))
}
var Noticer io.Writer = prefixed{os.Stderr}
// Print prints the given string to the Noticer.
func Print(s string) {
fmt.Fprint(Noticer, s)
}
// Println printslns the given string to the Noticer.
func Println(s string) {
fmt.Fprintln(Noticer, s)
}
// Printf printfs the given string to the Noticer.
func Printf(format string, a ...interface{}) {
fmt.Fprintf(Noticer, format, a...)
}

View File

@ -0,0 +1,18 @@
package deprecation
import (
"bytes"
"testing"
"github.com/stretchr/testify/require"
)
func TestNotice(t *testing.T) {
Print("before")
var b bytes.Buffer
Noticer = prefixed{&b}
Print("blah\n")
Printf("blah: %v\n", true)
Println("foobar")
require.Equal(t, "DEPRECATION WARNING: blah\nDEPRECATION WARNING: blah: true\nDEPRECATION WARNING: foobar\n", b.String())
}

View File

@ -11,6 +11,7 @@ import (
"github.com/AlekSi/pointer"
"github.com/Masterminds/semver/v3"
"github.com/goreleaser/chglog"
"github.com/goreleaser/nfpm/v2/deprecation"
"github.com/goreleaser/nfpm/v2/files"
"github.com/imdario/mergo"
"gopkg.in/yaml.v3"
@ -375,8 +376,8 @@ func Validate(info *Info) (err error) {
}
if len(info.EmptyFolders) > 0 {
fmt.Fprintf(os.Stderr, "DEPRECATION WARNING: 'empty_folders' is deprecated and "+
"will be removed in a future version, create content with type 'dir' and "+
deprecation.Println("'empty_folders' is deprecated and " +
"will be removed in a future version, create content with type 'dir' and " +
"directoy name as 'dst' instead")
for _, emptyFolder := range info.EmptyFolders {