Open soldni opened 1 year ago
Demo code of how the decorator could look like:
from functools import partial
import click
import springs as sp
@sp.dataclass
class Config:
other: int = 1
def click_parser(
ctx: click.Context, arg: click.Argument, val: tuple, /, config_cls: type
):
# NOTE: other flags are in `ctx.params`
# TODO: logic to merge cli args with config file goes here
...
def add_click(config_cls):
# TODO: need to add typing annotations (maybe)
# TODO: need to add all the flags a springs cli app requires
return click.argument(
"springs_config",
nargs=-1,
type=click.UNPROCESSED,
callback=partial(click_parser, config_cls=config_cls),
)
@click.command()
@click.option("-c", "--count", default=1, help="Number of greetings.")
@add_click(Config)
def main(count: int, springs_config: Config):
print(springs_config)
print(count)
if __name__ == "__main__":
main()
Worklog:
springs.commandline
so that logic to parse configurations is separate from creation of command line flags.click
that captures unused arguments.click
to map to flags in the current parser (should a user be able to customize them?)