Co-authored-by: Connor Davis <17688291+PoisonPhang@users.noreply.github.com> Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
co-authored by
Connor Davis
Julien Robert
parent
a4bd70895d
commit
d2f9634443
+9
-1
@@ -359,6 +359,14 @@ func GetClientContextFromCmd(cmd *cobra.Command) Context {
|
||||
// SetCmdClientContext sets a command's Context value to the provided argument.
|
||||
// If the context has not been set, set the given context as the default.
|
||||
func SetCmdClientContext(cmd *cobra.Command, clientCtx Context) error {
|
||||
cmd.SetContext(context.WithValue(cmd.Context(), ClientContextKey, &clientCtx))
|
||||
var cmdCtx context.Context
|
||||
|
||||
if cmd.Context() == nil {
|
||||
cmdCtx = context.Background()
|
||||
} else {
|
||||
cmdCtx = cmd.Context()
|
||||
}
|
||||
|
||||
cmd.SetContext(context.WithValue(cmdCtx, ClientContextKey, &clientCtx))
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user