Skip to content

Commit

Permalink
Merge pull request #377 from aiven/sort-cli-help-options
Browse files Browse the repository at this point in the history
  • Loading branch information
dogukancagatay authored Jan 17, 2024
2 parents a87f8c8 + 9e710ac commit 0276517
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 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,12 @@ 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().add_arguments(actions)

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

0 comments on commit 0276517

Please sign in to comment.