From 5104f3e7f00746b69745f2a6f4065f07edb28a9f Mon Sep 17 00:00:00 2001 From: Olzhas Arystanov Date: Tue, 7 May 2024 21:15:41 +0500 Subject: [PATCH] Use short description from docstring as usage help --- b2/_internal/arg_parser.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/b2/_internal/arg_parser.py b/b2/_internal/arg_parser.py index 364e6fcd..e9caab8f 100644 --- a/b2/_internal/arg_parser.py +++ b/b2/_internal/arg_parser.py @@ -46,7 +46,7 @@ def add_argument(self, action): if self.show_all: usages.append(f'(DEPRECATED) {choice.format_usage()}') else: - usages.append(choice.format_usage()) + usages.append(choice.format_usage(use_short_description=not self.show_all)) self.add_text(''.join(usages)) else: super().add_argument(action) @@ -112,6 +112,10 @@ def description(self): def description(self, value): self._raw_description = value + @property + def short_description(self): + return self.usage or self.description.split('\n', 1)[0] + def error(self, message): self.print_help() @@ -175,6 +179,14 @@ def _hide_duplicated_action_choices(self, action): yield action.choices = original_choices + def format_usage(self, use_short_description: bool = False): + if not use_short_description or not self.short_description: + return super().format_usage() + + formatter = self._get_formatter() + formatter.add_text(f"{self.prog} {self.short_description}") + return formatter.format_help() + SUPPORT_CAMEL_CASE_ARGUMENTS = False