eapp.make_flags_parser#
- etils.eapp.make_flags_parser(
- cls: etils.eapp.dataclass_flags._DataclassT,
- *,
- prog: str | None = None,
- description: str | None = None,
- **extra_kwargs,
Dataclass flag parser for absl.
Allow to define CLI flags through dataclasses.
Usage:
@dataclasses.dataclass class Args: user: str verbose: bool = False def main(args: Args): if args.verbose: print(args.user) if __name__ == '__main__': app.run(main, flags_parser=eapp.make_flags_parser(Args))
Allow to call your program with my_program –user=$USER –verbose
This is a wrapper around simple_parsing (lebrice/SimpleParsing). See documentation for details.
- Parameters:
cls – Dataclass containing the arguments to be parsed
prog – Program name. Forwarded to argparse.ArgumentParser
description – Description (auto-extracted from the __main__ docstring) Forwarded to argparse.ArgumentParser
**extra_kwargs – Extra arguments to be forwarded to argparse.ArgumentParser
- Returns:
flags_parser function, for app.run(main, flags_parser=…).