Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python option parser overwrite '-h'

Tags:

python

elf

I have the following options

parser = OptionParser()
parser.add_option('-a', '--all', action='store_true', dest='all', help='writes all header information')
parser.add_option('-h', '--file-header', action='store_true', dest='head',  help='prints the elf file header information')
parser.add_option('-l', '--program-header', action='store_true', dest='prog',  help='prints the program header')
parser.add_option('-S', '--section-header', action='store_true', dest='sec',  help='prints the section header')

When running the script I get the error message:

 optparse.OptionConflictError: option -h/--file-header: conflicting option string(s): -h

I know normally -h is reserved to display the help. But I'm trying to write an ELF file reader for some special elf files, and therefore I want to use the same commands like readelf. And readelf uses -h for printing the header information.

Is there any possibility to overwrite the -h option in the option parser or is that fixed?

like image 614
Rolf Lussi Avatar asked Feb 08 '23 14:02

Rolf Lussi


1 Answers

When creating the parser, pass add_help_option=False. Then you will be able to define it by yourself:

parser =  OptionParser(add_help_option=False)
like image 97
mic4ael Avatar answered Feb 27 '23 23:02

mic4ael