Search code examples
pythoncommand-line-interfacepython-click

Python Click Module Dict Return Value


In the documentation the usage of the click module is this way:

@click.command()
@click.argument('tgt')
@click.argument('fun')
def main(tgt, fun):
    #stuff here

How can I pass a dictionary which contains all arguments that need to be passed to the main function instead of passing each argument separately, i.e:

@click.command()
@click.argument('tgt')
@click.argument('fun')
def main(my_dict):
    print my_dict['tgt']
    print my_dict['fun']
    #stuff here

Solution

  • You can do -

    def main(**kargs):
    

    'kargs' will be a dictionary which will be having all the arguments.