-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Command.Context() returns nil instead of context.Background() #1582
Conversation
Looks good to me 👍 Could you squash the commits down before I merge though? |
Out of curiosity, what specific scenario does this address? Lines 915 to 918 in 6d2dc43
|
cac70a3
to
f5f90a2
Compare
@marckhouzam I often use package injection in a command's Run function func newFooCommand() *cobra.Command {
return &cobra.Command{ RunE: foo }
}
func foo(cmd *cobra.Command, args []string) error {
fs := afero.NewOsFs()
return bar(cmd, args, fs)
}
func bar(cmd *cobra.Command, args []string, fs afero.Fs) error {
// use cmd.Context
return nil
}
func TestFoo(t *testing.T) {
cmd := newFooCommand()
fs := afero.NewMemMapFs()
assert.NoError(t, bar(cmd, []string{}, fs))
} |
Now that we have a I'm just a little hesitant because maybe people will want to use |
From my perspective, #1551 should at least solve the issue I've described above (#1582 (comment)). However, if this PR isn't merged, the doc comment of the Command.Context method should be updated and state that nil is returned if no context has been set. |
After discussion we felt that there was more flexibility and less risk in allowing a And now that we have a The GoDoc was adjusted by #1639. I'm therefore going to close this but if you still feel something is missing, feel free to re-open. |
Merge spf13/cobra#1582 Closes #1578
Closes #1578