1
votes

In argparse, I want optional arguments to appear in the help list under optional arguments: but not in the usage text. I can use help=argparse.SUPPRESS in the argument to remove it from usage but this has the side effect of removing it from the argument descriptions in the help text.

Is it possible -- and if so, how -- to suppress the argument only in the usage.

Additionally, how would I go about replacing all of the optional arguments with a consolidated [--args] indicator in the usage.

1

1 Answers

0
votes

If you don't specify a usage message, it is auto-generated based on the arguments. If you don't like the auto-generated usage string, you can override it yourself at the time of creation of the parser:

parser = ArgumentParser(usage='my usage str')

You can not customize the auto-generated usage message to only suppress optional arguments, this is a use-it-or-lose-it thing. If you want to re-use code for a customized usage generator, your best bet will be to subclass a HelpFormatter and override the _format_usage method.