From 618bc00f8084be91329cbceb8094a7e5190a6c29 Mon Sep 17 00:00:00 2001 From: Juan Leni Date: Mon, 11 Feb 2019 16:06:55 +0100 Subject: [PATCH] Allow for explicit output to err/stderr --- command.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/command.go b/command.go index 58cc8732..3e97687a 100644 --- a/command.go +++ b/command.go @@ -1121,6 +1121,21 @@ func (c *Command) Printf(format string, i ...interface{}) { c.Print(fmt.Sprintf(format, i...)) } +// PrintErr is a convenience method to Print to the defined Err output, fallback to Stderr if not set. +func (c *Command) PrintErr(i ...interface{}) { + fmt.Fprint(c.ErrOrStderr(), i...) +} + +// PrintErrln is a convenience method to Println to the defined Err output, fallback to Stderr if not set. +func (c *Command) PrintErrln(i ...interface{}) { + c.Print(fmt.Sprintln(i...)) +} + +// PrintErrf is a convenience method to Printf to the defined Err output, fallback to Stderr if not set. +func (c *Command) PrintErrf(format string, i ...interface{}) { + c.Print(fmt.Sprintf(format, i...)) +} + // CommandPath returns the full path to this command. func (c *Command) CommandPath() string { if c.HasParent() {