Skip to content

Commit

Permalink
Alphabetically list any --options printed by --help.
Browse files Browse the repository at this point in the history
Longer lists of options are difficult for humans to read when they are
unsorted.
  • Loading branch information
neilhwatson committed Jan 16, 2024
1 parent a87f8c8 commit c69b0dd
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions aiven/client/argx.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from aiven.client import envdefault, pretty
from argparse import Action, ArgumentParser, Namespace
from os import PathLike
from typing import Any, Callable, cast, Collection, Mapping, NoReturn, Sequence, TextIO, TYPE_CHECKING, TypeVar
from typing import Any, Callable, cast, Collection, Iterable, Mapping, NoReturn, Sequence, TextIO, TYPE_CHECKING, TypeVar

import aiven.client.client
import argparse
Expand Down Expand Up @@ -98,7 +98,11 @@ class NextReleaseDeprecationNotice(ArgumentDeprecationNotice):


class CustomFormatter(argparse.RawDescriptionHelpFormatter):
"""Help formatter to display the default value only for integers and non-empty strings"""
"""Help formatter to display the default value only for integers and non-empty strings, and to sort --options alphabetically."""

def add_arguments(self, actions: Iterable[Action]) -> None:
actions = sorted(actions, key=lambda x: x.dest)
super(CustomFormatter, self).add_arguments(actions)

def _get_help_string(self, action: Action) -> str:
help_text = action.help or ""
Expand Down

0 comments on commit c69b0dd

Please # to comment.