utils

otto.utils.split_on_commas(values: list[str] | str) list[str]

Split a string or list of strings on commas into a flat list.

Parameters:

values – A single comma-separated string, or a list of such strings.

Returns:

A flat list of the individual values.

>>> split_on_commas("a,b,c")
['a', 'b', 'c']
>>> split_on_commas(["a,b", "c,d"])
['a', 'b', 'c', 'd']
>>> split_on_commas("single")
['single']
otto.utils.async_typer_command(f: Callable[[P], Coroutine[Any, Any, R]]) Callable[[P], R]
class otto.utils.Arg(variadic: bool = False, elem_type: type | None = None, name: str | None = None, help: str | None = None)

Bases: object

CLI overlay: force a parameter to a positional argument.

variadic=True makes it a space-separated list of elem_type (used for Python-union list params Typer can’t read, e.g. str | Sequence[...]). elem_type also overrides the CLI type for a scalar union. Imports no typer.

variadic : bool = False
elem_type : type | None = None
name : str | None = None
help : str | None = None
class otto.utils.Opt(elem_type: type | None = None, name: str | None = None, help: str | None = None)

Bases: object

CLI overlay: force a parameter to a --option. Imports no typer.

elem_type : type | None = None
name : str | None = None
help : str | None = None
otto.utils.cli_exposed(fn=None, *, name: str | None = None, help: str | None = None, success: str | None = None)

Mark a host coroutine method for auto-exposure as an otto host subcommand. name defaults to the method name with underscores dashed. success is an optional message printed on a successful (Status, "") result (e.g. “Transfer complete.”).

Usable bare (@cli_exposed) or called (@cli_exposed(name=..., ...)).

otto.utils.is_literal(value: Any, literal_type: type[T]) T

Raise a TypeError if value is not a valid member of the Literal type.

class otto.utils.Status(value)

Bases: Enum

General status enum for commands and tests.

>>> Status.Success
<Status.Success: 0>
>>> Status.Failed
<Status.Failed: 1>
>>> Status(0) is Status.Success
True
Success = 0
Failed = 1
Error = 2
Unstable = 3
Skipped = 4
property is_ok : bool

True for statuses that should be treated as passing (Success, Skipped).

class otto.utils.CommandStatus(command: str, output: str, status: Status, retcode: int)

Bases: NamedTuple

Result of a command execution on a host.

>>> result = CommandStatus("echo hi", "hi", Status.Success, 0)
>>> result.status
<Status.Success: 0>
>>> result.retcode
0
command : str

Command that was issued

output : str

Command output

status : Status

Command status

retcode : int

Command shell retcode