Skip to content

Commit

Permalink
Sort the help section alphabetically
Browse files Browse the repository at this point in the history
  • Loading branch information
stratakis committed Nov 5, 2021
1 parent 85ccafe commit 0b50a2f
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions barman/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
import logging
import os
import sys
from argparse import SUPPRESS, ArgumentTypeError, ArgumentParser
from argparse import SUPPRESS, ArgumentTypeError, ArgumentParser, HelpFormatter
if sys.version_info.major < 3:
from argparse import Action, _SubParsersAction, _ActionsContainer
import argcomplete
from collections import OrderedDict
from contextlib import closing
from functools import wraps

Expand Down Expand Up @@ -94,7 +95,14 @@ def add_parser(self, name, **kwargs):
# override argparse to register new subparser action by default
_ActionsContainer.__init__ = AliasedSubParsersAction._containerInit

p = ArgumentParser(epilog="Barman by EnterpriseDB (www.enterprisedb.com)")
class OrderedHelpFormatter(HelpFormatter):
def _format_usage(self, usage, actions, groups, prefix):
for action in actions:
if not action.option_strings:
action.choices = OrderedDict(sorted(action.choices.items()))
return super(OrderedHelpFormatter, self)._format_usage(usage, actions, groups, prefix)

p = ArgumentParser(epilog="Barman by EnterpriseDB (www.enterprisedb.com)", formatter_class = OrderedHelpFormatter)
p.add_argument(
"-v",
"--version",
Expand Down Expand Up @@ -159,6 +167,7 @@ def command(args):
def decorator(func):
parser = parent.add_parser(func.__name__.replace('_','-'), description=func.__doc__,
help=func.__doc__, aliases=cmd_aliases)
parent._choices_actions = sorted(parent._choices_actions, key=lambda x:x.dest)
for arg in args:
if (arg[1]):
parser.add_argument(*arg[0], **arg[2]).completer = arg[1]
Expand Down

0 comments on commit 0b50a2f

Please sign in to comment.