Python parser option overrides '-h'

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 you run the script, an error message appears:

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

I know that usually -h is reserved for displaying help. But I'm trying to write an ELF file read for some special elf files, and therefore I want to use the same commands as readelf. And readelf uses -h to print header information.

Is it possible to overwrite the -h parameter in the parameter parser or is this fixed?

+4
source share
1 answer

When creating a parser, go through add_help_option=False. Then you can determine it yourself:

parser =  OptionParser(add_help_option=False)
+8
source

Source: https://habr.com/ru/post/1615555/


All Articles