add --config by default when adding config options to a parser

This commit is contained in:
iclementine 2020-11-20 15:06:07 +08:00
parent 5b5eaaadac
commit 8af831ae3c
1 changed files with 4 additions and 0 deletions

View File

@ -25,6 +25,7 @@ class Config(attrdict.AttrDict):
def merge_args(self, args):
args_dict = vars(args)
args_dict.pop("config") # exclude config file path
nested_dict = flatdict.FlatDict(args_dict, delimiter=".").as_dict()
self.update(nested_dict)
@ -36,6 +37,9 @@ class Config(attrdict.AttrDict):
return flat
def add_options_to_parser(self, parser):
parser.add_argument(
"--config", type=str,
help="extra config file to override the default config")
flat = self.flatten()
g = parser.add_argument_group("config file options")
for k, v in flat.items():