You can silence help from arguments and groups using
argparse.SUPPRESS. However, there isn't a publicly documented way to
do the kind of introspection you'd probably need to get this to work.
However, if you don't mind using a few implementation details that
could change in the future, you could do something like:
class StoreOrSilenceAction(argparse.Action):
def __init__(self, group, **kwargs):
super(StoreOrSilenceAction, self).__init__(**kwargs)
self.group = group
def __call__(self, parser, namespace, value, option_string=None):
if value is None:
for action in parser._actions:
if action not in self.group._group_actions:
action.help = argparse.SUPPRESS
else:
setattr(namespace, self.dest, value)
parser = argparse.ArgumentParser()
a_group = parser.add_argument_group('a')
a_group.add_argument('-a', nargs='?', action=StoreOrSilenceAction,
group=a_group)
b_group = parser.add_argument_group('b')
b_group.add_argument('-b', nargs='?', action=StoreOrSilenceAction,
group=b_group)
args = parser.parse_args()
Basically, you make your options like --label take nargs='?', where
when there's no value, they silence the help for other things. You'd
probably need to do some extra error checking to make sure your user
didn't specify --label with no value but didn't ask for --help, but
maybe the above can at least get you started.
I guess this is probably a reason to add something like
parser.get_actions() and group.get_actions() so you wouldn't have to
rely on undocumented implementation details to do this kind of thing.
If you find that's the case, please feel free to file a feature
request on bugs.python.org.
Steve
--
Where did you get that preposterous hypothesis?
Did Steve tell you that?
--- The Hiphopopotamus
Yep, that looks like about what I would have done. Glad you got it working!