argclz.core.aliased_argument#

argclz.core.aliased_argument(options: str, *, aliases: dict[str, T], nargs: Literal['*', '+', '?', '...'] = ..., action: Literal['store', 'store_const', 'store_true', 'store_false', 'append', 'append_const', 'extend', 'count', 'help', 'version', 'boolean'] = ..., const: T = ..., default: T = ..., type: Type | Callable[[str], T] = ..., validator: Callable[[T], bool] = ..., choices: Sequence[str] = ..., help: str = ..., group: str | None = None, ex_group: str | None = None, metavar: str = ...) T[source]#

create an argument that supports shorthand aliases for specific constant values.

Usage

>>> class Example:
...     level: str = aliased_argument(
...         '--level',
...         aliases={
...             '--low': 'low',
...             '--mid': 'middle',
...             '--high': 'high',
...         },
...         choices=('low', 'middle', 'high')
...     )
Parameters:
  • options – options strings

  • aliases – a dictionary maps options to value.

  • action – argument action. Please see argparse.ArgumentParser.add_argument(action) for detailed.

  • nargs – number of following values. Please see argparse.ArgumentParser.add_argument(nargs) for detailed.

  • const – Please see argparse.ArgumentParser.add_argument(const) for detailed.

  • default – default value of argument. Please see argparse.ArgumentParser.add_argument(default) for detailed.

  • type – type caster with signature (str) -> T. Please see argparse.ArgumentParser.add_argument(type) for detailed.

  • validator – value validator with signature (T) -> bool.

  • choices – Please see argparse.ArgumentParser.add_argument(choices) for detailed.

  • required – Please see argparse.ArgumentParser.add_argument(required) for detailed.

  • hidden – hide this argument from help document.

  • help – help document for this argument.

  • group – group name of this argument.

  • ex_group – the mutually exclusive group name of this argument.

  • metavar – name of argument value. Please see argparse.ArgumentParser.add_argument(metavar) for detailed.