toolr._context¶
This module provides the Context class, which is passed to every command group function as the first argument.
ConsoleVerbosity ¶
Context ¶
Bases: Struct
Context object passed to every command group function as the first argument.
prompt ¶
prompt(
prompt: TextType,
expected_type: type[bool],
*,
default: bool | None = None,
show_default: bool = True,
) -> bool
prompt(
prompt: TextType,
expected_type: type[str],
*,
password: bool = True,
default: str | None = None,
case_sensitive: bool = True,
) -> str
prompt(
prompt: TextType,
expected_type: type[int],
*,
choices: list[str] | None = None,
default: int | None = None,
show_default: bool = True,
show_choices: bool = True,
) -> int
prompt(
prompt: TextType,
expected_type: type[str | int | float | bool]
| None = None,
*,
password: bool = False,
case_sensitive: bool = True,
choices: list[str] | None = None,
default: str | int | float | bool | None = None,
show_default: bool = True,
show_choices: bool = True,
) -> str | int | float | bool
Prompt the user for input.
This is a wrapper around rich.prompt.Prompt.ask.
See rich.prompt.Prompt.ask for more details.
Source code in python/toolr/_context.py
print ¶
print(
*args: ConsoleRenderable | RichCast | str, **kwargs: Any
) -> None
Print to stdout.
This is a wrapper around :func:rich.console.Console.print
.
See :func:rich.console.Console.print
for more details.
Source code in python/toolr/_context.py
debug ¶
Print debug message to stderr.
This is a wrapper around rich.console.Console.log.
See rich.console.Console.log for more details.
Source code in python/toolr/_context.py
info ¶
Print info message to stderr.
This is a wrapper around rich.console.Console.log.
See rich.console.Console.log for more details.
Source code in python/toolr/_context.py
warn ¶
Print warning message to stderr.
This is a wrapper around rich.console.Console.log.
See rich.console.Console.log for more details.
Source code in python/toolr/_context.py
error ¶
Print error message to stderr.
This is a wrapper around rich.console.Console.log.
See rich.console.Console.log for more details.
Source code in python/toolr/_context.py
exit ¶
Exit the command execution.
Source code in python/toolr/_context.py
run ¶
run(
*cmdline: str,
stream_output: bool = True,
capture_output: bool = False,
timeout_secs: float | None = None,
no_output_timeout_secs: float | None = None,
**kwargs: Any,
) -> CommandResult[str] | CommandResult[bytes]
Run a command with the given arguments.
This is a wrapper around toolr.utils.command.run that provides a simpler interface for command functions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cmdline
|
str
|
Command line to run |
()
|
stream_output
|
bool
|
Whether to stream output to stdout/stderr |
True
|
capture_output
|
bool
|
Whether to capture output to return |
False
|
timeout_secs
|
float | None
|
Maximum time to wait for command completion |
None
|
no_output_timeout_secs
|
float | None
|
Maximum time to wait without output |
None
|
kwargs
|
Any
|
Additional keyword arguments to pass to toolr.utils.command.run |
{}
|
Returns:
Type | Description |
---|---|
CommandResult[str] | CommandResult[bytes]
|
CommandResult instance. |
Source code in python/toolr/_context.py
chdir ¶
Change the working directory for this context.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str | Path
|
The new working directory path |
required |
Returns:
Type | Description |
---|---|
Iterator[Path]
|
Iterator yielding the new working directory as a Path object |
This is a context manager, so it should be used with 'with':
.. code-block:: python
with ctx.chdir("/some/path") as p:
# Do something in /some/path
# p is the Path object for /some/path