Counters#
Repeatable ‘counter’ arguments can be specified via tyro.conf.UseCounterAction
.
1from typing_extensions import Annotated
2
3import tyro
4from tyro.conf import UseCounterAction
5
6
7def main(
8 verbosity: UseCounterAction[int],
9 aliased_verbosity: Annotated[UseCounterAction[int], tyro.conf.arg(aliases=["-v"])],
10) -> None:
11 """Example showing how to use counter actions.
12
13 Args:
14 verbosity: Verbosity level.
15 aliased_verbosity: Same as above, but can also be specified with -v, -vv, -vvv, etc.
16 """
17 print("Verbosity level:", verbosity)
18 print("Verbosity level (aliased):", aliased_verbosity)
19
20
21if __name__ == "__main__":
22 tyro.cli(main)
python 04_additional/12_counters.py --help
usage: 12_counters.py [-h] [--verbosity] [--aliased-verbosity] Example showing how to use counter actions. ╭─ options ──────────────────────────────────────────────────────────────────╮ │ -h, --help show this help message and exit │ │ --verbosity Verbosity level. (repeatable) │ │ --aliased-verbosity, -v │ │ Same as above, but can also be specified with -v, -vv, │ │ -vvv, etc. (repeatable) │ ╰────────────────────────────────────────────────────────────────────────────╯
python 04_additional/12_counters.py --verbosity
Verbosity level: 1 Verbosity level (aliased): 0
python 04_additional/12_counters.py --verbosity --verbosity
Verbosity level: 2 Verbosity level (aliased): 0
python 04_additional/12_counters.py -vvv
Verbosity level: 0 Verbosity level (aliased): 3