Question#

class cli_interview_kit.Question[source]#

Bases: FrozenModel

One interview question.

Attributes:
keystr

Answer key, in snake_case; the flag is -- plus the key with dashes.

sectionstr

Interview section and help group.

kindLiteral[‘text’, ‘select’, ‘multiselect’, ‘confirm’, ‘int’, ‘list’, ‘pairs’, ‘per_item’, ‘custom’]

How the question is answered.

promptstr

Terminal prompt. For list and pairs it names one item; for per_item it may use {item}.

helpstr

What the answer means; the flag’s help.

choicestuple[str, …]

Fixed choices of a select, multiselect or per_item question.

choices_fromstr | None

Dynamic choices from the interview’s choices source of that name, after any fixed ones (per item for per_item).

flag_choices_fromstr | None

Further values the flag accepts that the prompt does not offer.

items_fromstr | None

The choices source listing a per_item question’s items.

labelsdict[str, str]

How choices are shown.

defaultstr | bool | int | None

The answer when nobody is asked, and the prompt’s starting value. A string may reference earlier text or select answers ({name}) and, for per_item, {item}.

default_fromstr | None

A dynamic default from the interview’s defaults source instead.

requiredbool

The answer has no safe default: a run that cannot prompt fails without the flag.

validatorCallable[[str], str] | None

Checks every answer, at the prompt and from the flag.

metavarstr | None

The flag’s value placeholder in help.

promptedbool

Whether the terminal interview asks it; False for settings only set by flag.

customstr | None

The custom kind of a custom question.

suggestions_fromstr | None

A choices source of suggested values for a free-text answer: listed under the input in a terminal and by --questions, never enforced.

groupstr | None

A group from Interview.groups an assistant may ask as one bundled question (“keep these defaults?”).

when_alltuple[Condition, …]

Asked only when every condition holds.

when_anytuple[Condition, …]

Asked only when at least one condition holds, if any are declared.

flagstr

The flag answering this question.

Methods

applies(context)

Return whether the question is asked, given the context so far.

describe_conditions()

Return when the question applies, as text.

placeholders()

Return the {name} placeholders of a string default.

property flag: str#

The flag answering this question.

applies(context: Mapping[str, Any]) → bool[source]#

Return whether the question is asked, given the context so far.

Parameters:
contextMapping[str, Any]

The values conditions see: options, answers and facts, by key.

Returns:
bool

Whether the question is asked.

describe_conditions() → str[source]#

Return when the question applies, as text.

Returns:
str

The conditions, joined with “and” and “or”.

placeholders() → list[str][source]#

Return the {name} placeholders of a string default.

Returns:
list[str]

The placeholder names; empty if the default is not a string.