Python Forum
Can argparse support undocumented options? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Can argparse support undocumented options? (/thread-29014.html)



Can argparse support undocumented options? - pjfarley3 - Aug-14-2020

Suppose I want to have options that I do not normally want to tell the user about in the help message, but which are parsed and processed by argparse like all other defined options. For example, debugging options useful to the developer but not to the regular user, but which the user could be instructed to use to help document or track down a problem.

Anyone looking at the source would be able to read about them of course, but they would not be presented using the --help option for normal use.

Is there a way to use argparse to support such options?

Peter


RE: Can argparse support undocumented options? - buran - Aug-14-2020

From argparse docs:
Quote:argparse supports silencing the help entry for certain options, by setting the help value to argparse.SUPPRESS:
>>> parser = argparse.ArgumentParser(prog='frobble')
>>> parser.add_argument('--foo', help=argparse.SUPPRESS)
>>> parser.print_help()
usage: frobble [-h]

optional arguments:
  -h, --help  show this help message and exit
metavar



RE: Can argparse support undocumented options? - bowlofred - Aug-14-2020

From Argparse documentation (deep inside...)

Quote:argparse supports silencing the help entry for certain options, by setting the help value to argparse.SUPPRESS:

>>>
>>> parser = argparse.ArgumentParser(prog='frobble')
>>> parser.add_argument('--foo', help=argparse.SUPPRESS)
>>> parser.print_help()
usage: frobble [-h]

optional arguments:
  -h, --help  show this help message and exit

Sigh, no ninja button...


RE: Can argparse support undocumented options? - pjfarley3 - Aug-14-2020

Thanks to both buran and bowlofred, I missed that in the documentation.

Peter