Provide a variable for writing output with a default of os.Stderr

main
Matt Farina 8 years ago
parent 75b97d09d9
commit 2a256d4c53

@ -228,11 +228,11 @@ func (a *App) Run(arguments []string) (err error) {
// DEPRECATED: Another entry point to the cli app, takes care of passing arguments and error handling
func (a *App) RunAndExitOnError() {
fmt.Fprintf(os.Stderr,
fmt.Fprintf(OutWriter,
"DEPRECATED cli.App.RunAndExitOnError. %s See %s\n",
contactSysadmin, runAndExitOnErrorDeprecationURL)
if err := a.Run(os.Args); err != nil {
fmt.Fprintln(os.Stderr, err)
fmt.Fprintln(OutWriter, err)
OsExiter(1)
}
}
@ -422,7 +422,7 @@ func HandleAction(action interface{}, context *Context) (err error) {
vals := reflect.ValueOf(action).Call([]reflect.Value{reflect.ValueOf(context)})
if len(vals) == 0 {
fmt.Fprintf(os.Stderr,
fmt.Fprintf(OutWriter,
"DEPRECATED Action signature. Must be `cli.ActionFunc`. %s See %s\n",
contactSysadmin, appActionDeprecationURL)
return nil

@ -8,6 +8,10 @@ import (
var OsExiter = os.Exit
// OutWriter is used to write output to the user. This can be anything
// implementing the io.Writer interface and defaults to os.Stderr.
var OutWriter = os.Stderr
type MultiError struct {
Errors []error
}
@ -69,7 +73,7 @@ func HandleExitCoder(err error) {
if exitErr, ok := err.(ExitCoder); ok {
if err.Error() != "" {
fmt.Fprintln(os.Stderr, err)
fmt.Fprintln(OutWriter, err)
}
OsExiter(exitErr.ExitCode())
return

@ -220,7 +220,7 @@ func (f IntSliceFlag) Apply(set *flag.FlagSet) {
s = strings.TrimSpace(s)
err := newVal.Set(s)
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
fmt.Fprintf(OutWriter, err.Error())
}
}
f.Value = newVal

@ -188,7 +188,7 @@ func printHelp(out io.Writer, templ string, data interface{}) {
err := t.Execute(w, data)
if err != nil {
// If the writer is closed, t.Execute will fail, and there's nothing
// we can do to recover. We could send this to os.Stderr if we need.
// we can do to recover. We could send this to OutWriter if we need.
return
}
w.Flush()

Loading…
Cancel
Save