Ordenar argparse ajuda em ordem alfabética
Estou usando o recurso argparse do Python (2.7) e gostaria de classificar automaticamente a ajuda que ele produz por ordem alfabética.
Por padrão, as entradas de ajuda são classificadas na ordem em que são adicionadas *, como em:
p = argparse.ArgumentParser(description='Load duration curves and other plots')
p.add_argument('--first', '-f', type=int, default=1, help='First Hour')
p.add_argument('--dur', '-d', type=int, default=-1, help='Duration in Hours. Use -1 for all')
p.add_argument('--title', '-t', help='Plot Title (for all plots), default=file name')
p.add_argument('--interp', '-i', action="store_true", default=True,
help='Use linear interpolation for smoother curves')
...
args = p.parse_args()
Que quando chamado comopython script -h
produz:
usage: script.py [-h] [--first FIRST] [--dur DUR] [--title TITLE] [--interp]
Load duration curves and other plots
optional arguments:
-h, --help show this help message and exit
--first FIRST, -f FIRST
First Hour
--dur DUR, -d DUR Duration in Hours. Use -1 for all
--title TITLE, -t TITLE
Plot Title (for all plots), default=file name
--interp, -i Use linear interpolation for smoother curves
É possível classificá-los automaticamente em ordem alfabética? Isso seria dur, primeiro, h, interp, título.
* Obviamente, o trabalho é manter manualmente adicionando entradas usando p.add_argument em ordem alfabética, mas estou tentando evitar fazê-lo.