As discussed one may reuse python click decorators from several scripts easily. However, with growing number of parameters
- the main function parameter list gets crowded and voids pylint
too-many-arguments
- the code processing these many parameters end up in WET programming
- if one has several scripts using these parameters, even multiple places of similar code have to be maintained
Hence, is there a way to create a class objects directly in the decorators to group parameters?
so, from a decorator function like this:
def common_options(mydefault=True):
def inner_func(function):
function = click.option('--unique-flag-1', is_flag=True)(function)
function = click.option('--bar', is_flag=True)(function)
function = click.option('--foo', is_flag=True, default=mydefault)(function)
return function
return inner_func
directly emit a class like this:
class CommonOptions:
def __init__(unique_flag_1, bar, foo):
self.unique_flag_1 = ....
could be directly emitted to
@click.command
@common_options()
def main(common_options: CommonOptions):
...