Let's suppose that we have already defined argument groups. Now I want to get access to one of them in order to add some extra argument. So what is the best way to do this in argparse? Now my approach looks like as follows:
def get_parser(self, ...):
parser = ...
matching_groups = (g for g in parser._action_groups
if g.title == 'group name')
group = next(matching_groups, None) or parser
group.add_argument('-s', '--some-new-argument', ...)
return parser
Is there any more elegant way that allows do not access 'protected' members directly?