Question#
- class cli_interview_kit.Question[source]#
Bases:
FrozenModelOne 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
listandpairsit names one item; forper_itemit may use{item}.- helpstr
What the answer means; the flag’s help.
- choicestuple[str, …]
Fixed choices of a
select,multiselectorper_itemquestion.- choices_fromstr | None
Dynamic choices from the interview’s
choicessource of that name, after any fixed ones (per item forper_item).- flag_choices_fromstr | None
Further values the flag accepts that the prompt does not offer.
- items_fromstr | None
The
choicessource listing aper_itemquestion’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, forper_item,{item}.- default_fromstr | None
A dynamic default from the interview’s
defaultssource 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;
Falsefor settings only set by flag.- customstr | None
The custom kind of a
customquestion.- suggestions_fromstr | None
A
choicessource 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.groupsan 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.
flagstrThe flag answering this question.
Methods
applies(context)Return whether the question is asked, given the context so far.
Return when the question applies, as text.
Return the
{name}placeholders of a string default.- 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.