Add support for CLI model fields
bswck opened this issue · comments
Describe the use case of a new functionality
Easily change settings just from process arguments. There's probably something like that in Hydra, unsure.
Example Use
from configzen import ConfigModel, ConfigField, cli_param
class MyModel(ConfigModel):
debug: bool = ConfigField(alias="debug_mode", cli_param=cli_param("-d", "--debug"))
verbose: bool = ConfigField.cli_param("-v", "--verbose")
def _cli_callback(self):
...
Integrate with argparse
:
- via arguments
parser = argparse.ArgumentParser() ... arguments = MyModel.cli.get_parser_arguments() for nf_args, options in arguments.items(): parser.add_argument(*nf_args, **options)
- as a subparser
parser = argparse.ArgumentParser() subparsers = parser.add_subparsers() ... subparsers.add_parser(MyModel.cli.as_parser("name"))
Integrate with click
:
if __name__ == "__main__":
MyModel.cli()
Integrate with typer
:
app = typer.Typer()
app.add_typer(MyModel.cli.typer())
Additional context
No response