Merge pull request #1191 from stellirin/master

feature: Add a App.Reader that defaults to os.Stdin
This commit is contained in:
Robert Liebowitz
2020-10-21 21:49:32 -04:00
committed by GitHub
2 changed files with 45 additions and 0 deletions

7
app.go
View File

@@ -72,6 +72,8 @@ type App struct {
Authors []*Author
// Copyright of the binary if any
Copyright string
// Reader reader to write input to (useful for tests)
Reader io.Reader
// Writer writer to write output to
Writer io.Writer
// ErrWriter writes error output
@@ -117,6 +119,7 @@ func NewApp() *App {
BashComplete: DefaultAppComplete,
Action: helpCommand.Action,
Compiled: compileTime(),
Reader: os.Stdin,
Writer: os.Stdout,
ErrWriter: os.Stderr,
}
@@ -160,6 +163,10 @@ func (a *App) Setup() {
a.Compiled = compileTime()
}
if a.Reader == nil {
a.Reader = os.Stdin
}
if a.Writer == nil {
a.Writer = os.Stdout
}