context
¶
-
class
invoke.context.
Context
(config=None)¶ Context-aware API wrapper & state-passing object.
Context
objects are created during command-line parsing (or, if desired, by hand) and used to share parser and configuration state with executed tasks (see State handling: the context).Specifically, the class offers wrappers for core API calls (such as
run
) which take into account CLI parser flags, configuration files, and/or changes made at runtime. It also acts as a proxy for itsconfig
attribute - see that attribute’s documentation for details.Instances of
Context
may be shared between tasks when executing sub-tasks - either the same context the caller was given, or an altered copy thereof (or, theoretically, a brand new one).-
__init__
(config=None)¶ Parameters: config – Config
object to use as the base configuration.Defaults to an anonymous/default
Config
instance.
-
config
= None¶ The fully merged
Config
object appropriate for this context.Config
settings (see their documentation for details) may be accessed like dictionary keys (ctx.config['foo']
) or object attributes (ctx.config.foo
).As a convenience shorthand, the
Context
object proxies to itsconfig
attribute in the same way - e.g.ctx['foo']
orctx.foo
returns the same value asctx.config['foo']
.
-
run
(command, **kwargs)¶ Execute a local shell command, honoring config options.
Specifically, this method instantiates a
Runner
subclass (according to therunner
config option; default isLocal
) and calls its.run
method withcommand
andkwargs
.See
Runner.run
for details oncommand
and the available keyword arguments.
-