tmt.cli package
Submodules
tmt.cli.status module
tmt status implementation
Module contents
Basic classes and code for tmt command line interface
- class tmt.cli.CliInvocation(context: Context | None, options: dict[str, Any])
Bases:
objectA single CLI invocation of a tmt subcommand.
Bundles together the Click context and options derived from it. A context alone might be good enough, but sometimes tmt needs to modify saved options. For custom command line options injected manually ‘sources’ is used to keep the parameter source.
Serves as a clear boundary between invocations of classes representing various tmt subcommands and groups.
- classmethod from_context(context: Context) CliInvocation
- classmethod from_options(options: dict[str, Any]) CliInvocation
Inject custom options coming from the command line
- property option_sources: dict[str, ParameterSource]
- options: dict[str, Any]
- class tmt.cli.Context(command: Command, parent: Context | None = None, info_name: str | None = None, obj: Any | None = None, auto_envvar_prefix: str | None = None, default_map: MutableMapping[str, Any] | None = None, terminal_width: int | None = None, max_content_width: int | None = None, resilient_parsing: bool = False, allow_extra_args: bool | None = None, allow_interspersed_args: bool | None = None, ignore_unknown_options: bool | None = None, help_option_names: List[str] | None = None, token_normalize_func: Callable[[str], str] | None = None, color: bool | None = None, show_default: bool | None = None)
Bases:
ContextCustom
click.Context-like class for typing purposes.Objects of this class are never instantiated, it serves only as a type stub in commands below, to simplify handling and static analysis of
context.obj. There is no added functionality, the only change is a much narrower type ofobjattribute.This class shall be used instead of the original
click.Context. Click is obviously not aware of our type annotations, andcontextobjects managed by Click would always be of typeclick.Context, we would just convince mypy theirobjattribute is no longerAny.- max_content_width: int | None
The maximum width of formatted content (None implies a sensible default which is 80 for most things).
- obj: ContextObject
the user object stored.
- class tmt.cli.ContextObject(cli_context: ~tmt.cli.Context, logger: ~tmt.log.Logger, common: ~tmt.utils.Common, fmf_context: ~tmt.utils.FmfContext, tree: ~tmt.base.Tree, steps: set[str] = <factory>, clean: ~tmt.base.Clean | None = None, clean_logger: ~tmt.log.Logger | None = None, clean_partials: ~collections.defaultdict[str, list[~typing.Callable[[], bool]]] = <factory>, run: ~tmt.base.Run | None = None)
Bases:
objectClick Context Object container.
In Click terms, this is “an arbitrary object of user data.” In this container, tmt CLI code stores all structures relevant for the command execution. The container itself is then attached to
click.Contextobject Click manages across commands.- clean_partials: defaultdict[str, list[Callable[[], bool]]]
- fmf_context: FmfContext
- steps: set[str]
- class tmt.cli.CustomGroup(name: str | None = None, commands: MutableMapping[str, Command] | Sequence[Command] | None = None, **attrs: Any)
Bases:
GroupCustom Click Group
- tmt.cli.EXCEPTION_LOGGER: Logger = <Logger: name=_tmt_bootstrap verbosity=0 debug=0 quiet=False topics=set() apply_colors_output=True apply_colors_logging=True>
A logger to use for exception logging.
Warning
This logger should be used with utmost care for logging exceptions only, no other traffic should be allowed. On top of that, the exception logging is handled by a dedicated function,
tmt.utils.show_exception()- if you find yourself in need of logging an exception somewhere in the code, and you think about using this logger or callingshow_exception()explicitly, it is highly likely you are not on the right track.
- class tmt.cli.HelpFormatter(indent_increment: int = 2, width: int | None = None, max_width: int | None = None)
Bases:
HelpFormatterCustom help formatter capable of rendering ReST syntax
- write_dl(rows: Sequence[tuple[str, str]], col_max: int = 30, col_spacing: int = 2) None
Writes a definition list into the buffer. This is how options and commands are usually formatted.
- Parameters:
rows – a list of two item tuples for the terms and values.
col_max – the maximum width of the first column.
col_spacing – the number of spaces between the first and second column.
- class tmt.cli.TmtExitCode(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)
Bases:
IntEnum- ALL_TESTS_SKIPPED = 4
Tests were executed, and all reported the
skipresult.
- ERROR = 2
Errors occurred during test execution.
- FAIL = 1
There was a fail or warn identified, but no error.
- NO_RESULTS_FOUND = 3
No test results found.
- SUCCESS = 0
At least one test passed, there was no fail, warn or error.
- tmt.cli.pass_context(fn: Callable[Concatenate[Context, P], R]) Callable[P, R]
Custom
click.pass_context()-like decorator.Complementing the
Context, the goal of this decorator to announce the correct type of thecontextparameter. The original decorator annotates the parameter asclick.Context, but that is not what our command callables accept. So, on this boundary between tmt code andclickAPI, we trick type checkers by isolating the necessarytype: ignore[arg-type].