From 9e710ac772d4d405584c33f3d51651f8fba4251d Mon Sep 17 00:00:00 2001 From: Neil Watson Date: Tue, 16 Jan 2024 11:04:04 -0500 Subject: [PATCH] Alphabetically list any `--options` printed by `--help`. Longer lists of options are difficult for humans to read when they are unsorted. --- aiven/client/argx.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/aiven/client/argx.py b/aiven/client/argx.py index 4b54fa5..31a154e 100644 --- a/aiven/client/argx.py +++ b/aiven/client/argx.py @@ -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 @@ -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 ""