Interview#

class cli_interview_kit.Interview[source]#

Bases: FrozenModel

A command’s questions and consents, and where their dynamic parts come from.

Attributes:
questionstuple[Question, …]

The questions, in the order they are asked.

consentstuple[Consent, …]

The confirmations the command may ask for while it runs.

choicesdict[str, Callable[[Mapping[str, Any], str | None], Sequence[str]]]

Dynamic choice, item and suggestion sources, by name.

defaultsdict[str, Callable[[Mapping[str, Any], str | None], str | None]]

Dynamic default sources, by name.

offlinefrozenset[str]

The choice sources that are local and cheap: --questions lists their values and only names the others.

factsCallable[[Mapping[str, Any]], Mapping[str, Any]] | None

Facts derived from the answers and options, for conditions.

custom_kindsdict[str, CustomKind]

The custom kinds the questions use, by name.

groupsdict[str, str]

Bundled question groups, by name, each with what it covers in one line.

consent_keysfrozenset[str]

The keys of the declared consents.

Methods

add_arguments(parser)

Add one flag per question to parser, grouped by section.

run(console, interaction, flag_values, options)

Answer every applicable question from its flag, a prompt, or its default.

document(command_line, options)

Return the interview as the document --questions prints.

property consent_keys: frozenset[str]#

The keys of the declared consents.

add_arguments(parser: ArgumentParser) → None[source]#

Add one flag per question to parser, grouped by section.

Parameters:
parserArgumentParser

The command’s argument parser.

run(console: Console, interaction: Interaction, flag_values: Mapping[str, Any], options: Mapping[str, Any]) → dict[str, Any][source]#

Answer every applicable question from its flag, a prompt, or its default.

Parameters:
consoleConsole

Where to ask.

interactionInteraction

Whether the run may prompt.

flag_valuesMapping[str, Any]

The parsed flags, by question key; None or [] if not given.

optionsMapping[str, Any]

The command’s option values, which conditions may test.

Returns:
dict[str, Any]

The answers of the questions that apply, by key.

Raises:
CliError

A flag answers a question that does not apply, a value fails validation, or a run that cannot prompt misses a required answer.

document(command_line: str, options: Sequence[Mapping[str, Any]]) → dict[str, Any][source]#

Return the interview as the document --questions prints.

Parameters:
command_linestr

How the command is invoked, e.g. mytool deploy.

optionsSequence[Mapping[str, Any]]

The command’s plain options, described.

Returns:
dict[str, Any]

The document: the questions, consents and options, with how an assistant asks them.