Allow a writer to be set that represents Stdout so that redirection of App output may occur.

This commit is contained in:
John Hopper
2014-06-12 00:39:13 -07:00
parent bb9189510a
commit 60e3dcaf6d
4 changed files with 87 additions and 30 deletions

View File

@@ -2,6 +2,7 @@ package cli
import (
"fmt"
"io"
"io/ioutil"
"strings"
)
@@ -70,18 +71,18 @@ func (c Command) Run(ctx *Context) error {
}
if err != nil {
fmt.Printf("Incorrect Usage.\n\n")
io.WriteString(ctx.App.Stdout, fmt.Sprintf("Incorrect Usage.\n\n"))
ShowCommandHelp(ctx, c.Name)
fmt.Println("")
io.WriteString(ctx.App.Stdout, fmt.Sprintln(""))
return err
}
nerr := normalizeFlags(c.Flags, set)
if nerr != nil {
fmt.Println(nerr)
fmt.Println("")
io.WriteString(ctx.App.Stdout, fmt.Sprintln(nerr))
io.WriteString(ctx.App.Stdout, fmt.Sprintln(""))
ShowCommandHelp(ctx, c.Name)
fmt.Println("")
io.WriteString(ctx.App.Stdout, fmt.Sprintln(""))
return nerr
}
context := NewContext(ctx.App, set, ctx.globalSet)