Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Propagate App.Reader to subcommands #1225

Merged
merged 1 commit into from Jan 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 33 additions & 0 deletions app_test.go
Expand Up @@ -897,6 +897,39 @@ func TestApp_SetStdin(t *testing.T) {
}
}

func TestApp_SetStdin_Subcommand(t *testing.T) {
buf := make([]byte, 12)

app := &App{
Name: "test",
Reader: strings.NewReader("Hello World!"),
Commands: []*Command{
{
Name: "command",
Subcommands: []*Command{
{
Name: "subcommand",
Action: func(c *Context) error {
_, err := c.App.Reader.Read(buf)
return err
},
},
},
},
},
}

err := app.Run([]string{"test", "command", "subcommand"})

if err != nil {
t.Fatalf("Run error: %s", err)
}

if string(buf) != "Hello World!" {
t.Error("App did not read input from desired reader.")
}
}

func TestApp_SetStdout(t *testing.T) {
var w bytes.Buffer

Expand Down
1 change: 1 addition & 0 deletions command.go
Expand Up @@ -243,6 +243,7 @@ func (c *Command) startApp(ctx *Context) error {
app.Version = ctx.App.Version
app.HideVersion = true
app.Compiled = ctx.App.Compiled
app.Reader = ctx.App.Reader
app.Writer = ctx.App.Writer
app.ErrWriter = ctx.App.ErrWriter
app.ExitErrHandler = ctx.App.ExitErrHandler
Expand Down