Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for CLI model fields #12

Open
bswck opened this issue Aug 17, 2023 · 0 comments
Open

Add support for CLI model fields #12

bswck opened this issue Aug 17, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@bswck
Copy link
Owner

bswck commented Aug 17, 2023

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:

  1. via arguments
    parser = argparse.ArgumentParser()
    ...
    arguments = MyModel.cli.get_parser_arguments()
    for nf_args, options in arguments.items():
        parser.add_argument(*nf_args, **options)
  2. 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

@bswck bswck added the enhancement New feature or request label Aug 17, 2023
@bswck bswck added this to OSS Dec 8, 2023
@bswck bswck moved this to Todo in OSS Dec 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: TO DO
Development

No branches or pull requests

1 participant