Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

suppress one of the options from help when using optparse in python

Consider the following:

parser.add_option("-f", "--file", "--secret", action = "append", type = "string", dest = "filename", default = [], help = "specify the files")

I would like to hide the --secret option from the user when help is invoked. Can I do this in the following way?

parser.add_option("-f", "--file", action = "append", type = "string", dest = "filename", default = [], help = "specify the files")
parser.add_option("--secret", action = "append", type = "string", dest = "filename", default = [], help = "specify the files")

Am I missing any hidden issue by doing so?If so, can anyone suggest an alternative way to achieve this.

like image 588
user2242512 Avatar asked Sep 05 '25 03:09

user2242512


1 Answers

Try the help=SUPPRESS_HELP trick (see docs):

from optparse import OptionParser, SUPPRESS_HELP

parser.add_option("-f", "--file", action = "append", type = "string", dest = "filename", default = [], help = "specify the files")
parser.add_option("--secret", action = "append", type = "string", dest = "filename", default = [], help=SUPPRESS_HELP)
like image 147
shx2 Avatar answered Sep 08 '25 00:09

shx2