Is it possible to remove or disable an argument in argparse, such that it does not show in the help? How?
It is easy to add new arguments:
Although hpaulj answer is great, in my case using just parser._remove_action(action) was not removing from the "positional arguments" help the removed action. My workaround was to remove it also from the _action_group
def remove_option(parser, arg):
for action in parser._actions:
if (vars(action)['option_strings']
and vars(action)['option_strings'][0] == arg) \
or vars(action)['dest'] == arg:
parser._remove_action(action)
for action in parser._action_groups:
vars_action = vars(action)
var_group_actions = vars_action['_group_actions']
for x in var_group_actions:
if x.dest == arg:
var_group_actions.remove(x)
return