Python Forum
Can argparse support undocumented options?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can argparse support undocumented options?
#1
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
Reply
#2
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
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...
Reply
#4
Thanks to both buran and bowlofred, I missed that in the documentation.

Peter
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Bug argparse io issue pyDream 8 702 Apr-02-2024, 12:42 PM
Last Post: pyDream
  Performance options for sys.stdout.writelines dgrunwal 11 3,157 Aug-23-2022, 10:32 PM
Last Post: Pedroski55
  Not able to figure out what is wrong with argparse radioactive9 31 8,617 Mar-16-2022, 07:50 PM
Last Post: deanhystad
  argparse --help in one line. Denial 1 2,004 Sep-20-2020, 03:38 PM
Last Post: deanhystad
  Argparse error when inputting values tqader 2 2,891 Sep-11-2020, 07:42 PM
Last Post: buran
  Why this pycharm warning for argparse formatter_class value? pjfarley3 2 2,142 Sep-09-2020, 05:23 AM
Last Post: pjfarley3
  In ArgParse, can two compatible formatter_class values be used? pjfarley3 2 2,601 Jul-31-2020, 02:01 PM
Last Post: pjfarley3
  Help with options raiden 1 1,942 Aug-30-2019, 12:57 AM
Last Post: scidam
  Why am I getting KeyError 'file' when using argparse? Mike Ru 1 3,085 Jun-09-2019, 04:48 PM
Last Post: metulburr
  How can I get some arguments using argparse? Mike Ru 0 1,888 Jun-05-2019, 12:57 PM
Last Post: Mike Ru

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020