Here is the code,
Code:
@click.option("--config",callback=read_config, type=click.File('r'))
def cli(ctx,**kwargs):
...
Here the function read_config is defined as,
Code:
def read_config(ctx, param, value):
if not value:
return {}
import json
def underline_dict(d):
if not isinstance(d, dict):
return d
return dict((k.replace('-', '_'), underline_dict(v)) for k, v in dix.iteritems(d))
global myconfig
myconfig = underline_dict(json.load(value))
return myconfig
Here is the config file called config.json referred by --config looks like the following,
Code:
key1:value1
key2:value2
key3:value3
My question is that what happens when we call function cli with the option of config file config.json? Thanks.