Other types#

Feud provides the following additional types for common CLI needs.

Tip

All of the types listed on this page are easily accessible from the feud.typing module.

It is recommended to import the feud.typing module with an alias such as t for convenient short-hand use, e.g.

from feud import typing as t

t.Counter  # feud.typing.custom.Counter
t.concounter  # feud.typing.custom.concounter

Counting types#

feud.typing.custom.Counter#

Keep count of a repeated command-line option.

Examples

>>> import feud
>>> from feud.typing import Counter
>>> @feud.alias(verbose="-v")
... def func(*, verbose: Counter) -> int:
...     return verbose
>>> feud.run(func, ["-vvv"], standalone_mode=False)
3

alias of Annotated[int]

feud.typing.custom.concounter(*, strict=None, gt=None, ge=None, lt=None, le=None, multiple_of=None)#

Wrap pydantic.types.conint to allow for constrained counting options.

Parameters:
  • strict (bool | None) – Whether to validate the integer in strict mode. Defaults to None.

  • gt (int | None) – The value must be greater than this.

  • ge (int | None) – The value must be greater than or equal to this.

  • lt (int | None) – The value must be less than this.

  • le (int | None) – The value must be less than or equal to this.

  • multiple_of (int | None) – The value must be a multiple of this.

Return type:

The wrapped pydantic.types.conint type.

Examples

>>> import feud
>>> from feud.typing import concounter
>>> @feud.alias(verbose="-v")
... def func(*, verbose: concounter(le=3)) -> int:
...     return verbose
>>> feud.run(func, ["-vvv"], standalone_mode=False)
3