MCPcopy
hub / github.com/PokemonGoF/PokemonGo-Bot / add_config

Function add_config

pokecli.py:847–865  ·  view source on GitHub ↗
(parser, json_config, short_flag=None, long_flag=None, **kwargs)

Source from the content-addressed store, hash-verified

845
846
847def add_config(parser, json_config, short_flag=None, long_flag=None, **kwargs):
848 if not long_flag:
849 raise Exception('add_config calls requires long_flag parameter!')
850
851 full_attribute_path = long_flag.split('--')[1]
852 attribute_name = full_attribute_path.split('.')[-1]
853
854 if '.' in full_attribute_path: # embedded config!
855 embedded_in = full_attribute_path.split('.')[0: -1]
856 for level in embedded_in:
857 json_config = json_config.get(level, {})
858
859 if 'default' in kwargs:
860 kwargs['default'] = json_config.get(attribute_name, kwargs['default'])
861 if short_flag:
862 args = (short_flag, long_flag)
863 else:
864 args = (long_flag,)
865 parser.add_argument(*args, **kwargs)
866
867
868def fix_nested_config(config):

Callers 1

init_configFunction · 0.85

Calls 1

getMethod · 0.45

Tested by

no test coverage detected