feature: Add a App.Reader that defaults to os.Stdin

Closes: #1190
This commit is contained in:
Adam Farden
2020-10-02 12:39:44 +02:00
parent f53989457f
commit 342ce5d654
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
}