-
-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add deprecation notice interface (#399)
* feat: add deprecation notice interface * fix: use a simple writer * fix: use println
- Loading branch information
Showing
4 changed files
with
54 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters