mirror of
https://github.com/spf13/cobra
synced 2025-05-05 12:57:22 +00:00
Add EnableAlwaysReplaceContexts
This commit is contained in:
parent
2a5277810f
commit
0cdd1b3479
2 changed files with 6 additions and 1 deletions
5
cobra.go
5
cobra.go
|
@ -49,6 +49,11 @@ var EnablePrefixMatching = false
|
|||
// To disable sorting, set it to false.
|
||||
var EnableCommandSorting = true
|
||||
|
||||
// EnableAlwaysReplaceContexts changes the behaviour of contexts being passed to child commands. By default a child
|
||||
// command's context will be set to its parents context on the first run, but not subsequent runs.
|
||||
// To pass contexts to children always, set this to true.
|
||||
var EnableAlwaysReplaceContexts = false
|
||||
|
||||
// MousetrapHelpText enables an information splash screen on Windows
|
||||
// if the CLI is started from explorer.exe.
|
||||
// To disable the mousetrap, just set this variable to blank string ("").
|
||||
|
|
|
@ -967,7 +967,7 @@ func (c *Command) ExecuteC() (cmd *Command, err error) {
|
|||
|
||||
// We have to pass global context to children command
|
||||
// if context is present on the parent command.
|
||||
if cmd.ctx == nil {
|
||||
if cmd.ctx == nil || EnableAlwaysReplaceContexts {
|
||||
cmd.ctx = c.ctx
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue