Add EnableAlwaysReplaceContexts

This commit is contained in:
KernelDeimos 2021-08-09 17:13:28 -04:00 committed by Eric Dubé
parent 2a5277810f
commit 0cdd1b3479
2 changed files with 6 additions and 1 deletions

View file

@ -49,6 +49,11 @@ var EnablePrefixMatching = false
// To disable sorting, set it to false. // To disable sorting, set it to false.
var EnableCommandSorting = true 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 // MousetrapHelpText enables an information splash screen on Windows
// if the CLI is started from explorer.exe. // if the CLI is started from explorer.exe.
// To disable the mousetrap, just set this variable to blank string (""). // To disable the mousetrap, just set this variable to blank string ("").

View file

@ -967,7 +967,7 @@ func (c *Command) ExecuteC() (cmd *Command, err error) {
// We have to pass global context to children command // We have to pass global context to children command
// if context is present on the parent command. // if context is present on the parent command.
if cmd.ctx == nil { if cmd.ctx == nil || EnableAlwaysReplaceContexts {
cmd.ctx = c.ctx cmd.ctx = c.ctx
} }