zabgrab.model.choice

Choice values: a list of options plus a rule for selecting between them.

Config keys that support choices accept either a plain value or a table such as { choices = ["a", "b"], select = "all" }.

Module Attributes

SINGLE_TAG

Tags used by the discriminated union below.

Functions

choice_or(type_)

Make the type of a setting that takes a value or a choice of values.

Classes

Choice(*, choices[, select])

A list of options and a selection rule.

Select(*values)

How to select between the options of a Choice.

class zabgrab.model.choice.Select(*values)[source]

Bases: StrEnum

How to select between the options of a Choice.

ALL

Use every option, stacking the results.

PROMPT

Ask the user (an error if non-interactive). The only one allowed for servers, since a fetch uses one server.

FIRST

Use the first option that works (for hosts, the first with matching items).

class zabgrab.model.choice.Choice(*, choices, select=Select.PROMPT)[source]

Bases: BaseModel, Generic[T]

A list of options and a selection rule.

Parameters:
choices

The options, without duplicates.

Type:

list

select

How to choose between them.

Type:

Select

model_config = {'extra': 'forbid', 'frozen': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

zabgrab.model.choice.SINGLE_TAG = '<value>'

Tags used by the discriminated union below. They appear in validation error locations and are stripped when errors are formatted for the user. They contain characters that are invalid in names, so they can’t clash with config keys.

zabgrab.model.choice.choice_or(type_)[source]

Make the type of a setting that takes a value or a choice of values.

A generic type alias can’t express this: Choice[T] is a concrete pydantic class, so substituting T later doesn’t reach it.

Parameters:
  • type (type) – The type of a single value.

  • type_ (Any)

Returns:

type – A pydantic type accepting a type_ or a Choice of type_.

Return type:

Any