| 18 | |
| 19 | class ParamGroup: |
| 20 | def __init__(self, parser: ArgumentParser, name : str, fill_none = False): |
| 21 | group = parser.add_argument_group(name) |
| 22 | for key, value in vars(self).items(): |
| 23 | shorthand = False |
| 24 | if key.startswith("_"): |
| 25 | shorthand = True |
| 26 | key = key[1:] |
| 27 | t = type(value) |
| 28 | value = value if not fill_none else None |
| 29 | if shorthand: |
| 30 | if t == bool: |
| 31 | group.add_argument("--" + key, ("-" + key[0:1]), default=value, action="store_true") |
| 32 | else: |
| 33 | group.add_argument("--" + key, ("-" + key[0:1]), default=value, type=t) |
| 34 | else: |
| 35 | if t == bool: |
| 36 | group.add_argument("--" + key, default=value, action="store_true") |
| 37 | else: |
| 38 | group.add_argument("--" + key, default=value, type=t) |
| 39 | |
| 40 | def extract(self, args): |
| 41 | group = GroupParams() |