Application reference¶
Application ¶
This class is never imported directly. Instead, use the dda.cli.base.pass_app
decorator to pass an instance of this class to your command.
from __future__ import annotations
from typing import TYPE_CHECKING
from dda.cli.base import dynamic_command, pass_app
if TYPE_CHECKING:
from dda.cli.application import Application
@dynamic_command(short_help="Some command")
@pass_app
def cmd(app: Application) -> None:
"""
Long description of the command.
"""
app.display_waiting("Running some command")
abort ¶
Gracefully terminate the application with an optional error message. The message is appended to the last error message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text | str | The error message to display. | '' |
code | int | The exit code to use. | 1 |
display ¶
Output text to stdout using the info
style regardless of the configured verbosity level.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text | str | The text to output. | '' |
Other Parameters:
Name | Type | Description |
---|---|---|
**kwargs | Any | Additional keyword arguments to pass to the |
display_critical ¶
Output text to stderr using the error
style regardless of the configured verbosity level.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text | str | The text to output. | '' |
Other Parameters:
Name | Type | Description |
---|---|---|
**kwargs | Any | Additional keyword arguments to pass to the |
display_error ¶
Output text using the error
style if the configured verbosity level is at least Verbosity.ERROR
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text | str | The text to output. | '' |
stderr | bool | Whether to output to stderr. | True |
Other Parameters:
Name | Type | Description |
---|---|---|
**kwargs | Any | Additional keyword arguments to pass to the |
display_warning ¶
Output text using the warning
style if the configured verbosity level is at least Verbosity.WARNING
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text | str | The text to output. | '' |
stderr | bool | Whether to output to stderr. | True |
Other Parameters:
Name | Type | Description |
---|---|---|
**kwargs | Any | Additional keyword arguments to pass to the |
display_info ¶
Output text using the info
style if the configured verbosity level is at least Verbosity.INFO
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text | str | The text to output. | '' |
stderr | bool | Whether to output to stderr. | True |
Other Parameters:
Name | Type | Description |
---|---|---|
**kwargs | Any | Additional keyword arguments to pass to the |
display_success ¶
Output text using the success
style if the configured verbosity level is at least Verbosity.INFO
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text | str | The text to output. | '' |
stderr | bool | Whether to output to stderr. | True |
Other Parameters:
Name | Type | Description |
---|---|---|
**kwargs | Any | Additional keyword arguments to pass to the |
display_waiting ¶
Output text using the waiting
style if the configured verbosity level is at least Verbosity.INFO
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text | str | The text to output. | '' |
stderr | bool | Whether to output to stderr. | True |
Other Parameters:
Name | Type | Description |
---|---|---|
**kwargs | Any | Additional keyword arguments to pass to the |
display_debug ¶
display_debug(
text: str = "",
level: int = VERBOSE,
*,
stderr: bool = True,
**kwargs: Any,
) -> None
Output text using the debug
style if the configured verbosity level is between Verbosity.VERBOSE
and Verbosity.TRACE
(inclusive).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text | str | The text to output. | '' |
level | int | The verbosity level. | VERBOSE |
stderr | bool | Whether to output to stderr. | True |
Other Parameters:
Name | Type | Description |
---|---|---|
**kwargs | Any | Additional keyword arguments to pass to the |
display_table ¶
Display a table with the given data using the success
style for the keys.
The following data:
{
"key1": {
"nested1": {
"str": "text",
"int": 1,
"float": 1.0,
"bool": True,
"list": ["foo", 2, "bar"],
},
},
}
would be displayed as:
┌──────┬─────────────────────────────────────────────┐
│ key1 │ ┌─────────┬───────────────────────────────┐ │
│ │ │ nested1 │ ┌───────┬───────────────────┐ │ │
│ │ │ │ │ str │ text │ │ │
│ │ │ │ │ int │ 1 │ │ │
│ │ │ │ │ float │ 1.0 │ │ │
│ │ │ │ │ bool │ True │ │ │
│ │ │ │ │ list │ ['foo', 2, 'bar'] │ │ │
│ │ │ │ └───────┴───────────────────┘ │ │
│ │ └─────────┴───────────────────────────────┘ │
└──────┴─────────────────────────────────────────────┘
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data | dict[str, Any] | The data to display. | required |
display_syntax ¶
status ¶
Display a status indicator with the configured spinner. If the session is not interactive, the status indicator will be displayed as a waiting message.
The returned object must be used as a context manager.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args | Any | Additional arguments to pass to the | () |
**kwargs | Any | Additional keyword arguments to pass to the | {} |
prompt ¶
Prompt the user for input.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args | Any | Additional arguments to pass to the | () |
**kwargs | Any | Additional keyword arguments to pass to the | {} |
Returns:
Type | Description |
---|---|
str | The user's input. |
confirm ¶
Prompt the user for confirmation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args | Any | Additional arguments to pass to the | () |
**kwargs | Any | Additional keyword arguments to pass to the | {} |
Returns:
Type | Description |
---|---|
bool | Whether the user confirmed the action. |