| 1 |
from importlib import metadata |
| 2 |
from typing import Any |
| 3 |
|
| 4 |
from .collection import Collection # noqa |
| 5 |
from .config import Config # noqa |
| 6 |
from .context import Context, MockContext # noqa |
| 7 |
from .exceptions import ( # noqa |
| 8 |
AmbiguousEnvVar, |
| 9 |
AuthFailure, |
| 10 |
CollectionNotFound, |
| 11 |
CommandTimedOut, |
| 12 |
Exit, |
| 13 |
ParseError, |
| 14 |
PlatformError, |
| 15 |
ResponseNotAccepted, |
| 16 |
SubprocessPipeError, |
| 17 |
ThreadException, |
| 18 |
UncastableEnvVar, |
| 19 |
UnexpectedExit, |
| 20 |
UnknownFileType, |
| 21 |
UnpicklableConfigMember, |
| 22 |
WatcherError, |
| 23 |
) |
| 24 |
from .executor import Executor # noqa |
| 25 |
from .loader import FilesystemLoader # noqa |
| 26 |
from .parser import Argument, Parser, ParserContext, ParseResult # noqa |
| 27 |
from .program import Program # noqa |
| 28 |
from .runners import Failure, Local, Promise, Result, Runner # noqa |
| 29 |
from .tasks import Call, Task, call, task # noqa |
| 30 |
from .terminals import pty_size # noqa |
| 31 |
from .watchers import FailingResponder, Responder, StreamWatcher # noqa |
| 32 |
|
| 33 |
__version__ = metadata.version("invoke") |
| 34 |
|
| 35 |
|
| 36 |
def run(command: str, **kwargs: Any) -> Result: |
| 37 |
""" |
| 38 |
Run ``command`` in a subprocess and return a `.Result` object. |
| 39 |
|
| 40 |
See `.Runner.run` for API details. |
| 41 |
|
| 42 |
.. note:: |
| 43 |
This function is a convenience wrapper around Invoke's `.Context` and |
| 44 |
`.Runner` APIs. |
| 45 |
|
| 46 |
Specifically, it creates an anonymous `.Context` instance and calls its |
| 47 |
`~.Context.run` method, which in turn defaults to using a `.Local` |
| 48 |
runner subclass for command execution. |
| 49 |
|
| 50 |
.. versionadded:: 1.0 |
| 51 |
""" |
| 52 |
return Context().run(command, **kwargs) |
| 53 |
|
| 54 |
|
| 55 |
def sudo(command: str, **kwargs: Any) -> Result: |
| 56 |
""" |
| 57 |
Run ``command`` in a ``sudo`` subprocess and return a `.Result` object. |
| 58 |
|
| 59 |
See `.Context.sudo` for API details, such as the ``password`` kwarg. |
| 60 |
|
| 61 |
.. note:: |
| 62 |
This function is a convenience wrapper around Invoke's `.Context` and |
| 63 |
`.Runner` APIs. |
| 64 |
|
| 65 |
Specifically, it creates an anonymous `.Context` instance and calls its |
| 66 |
`~.Context.sudo` method, which in turn defaults to using a `.Local` |
| 67 |
runner subclass for command execution (plus sudo-related bits & |
| 68 |
pieces). |
| 69 |
|
| 70 |
.. versionadded:: 1.4 |
| 71 |
""" |
| 72 |
return Context().sudo(command, **kwargs) |