Skip to content

Commit

Permalink
Use short description from docstring as usage help
Browse files Browse the repository at this point in the history
  • Loading branch information
olzhasar-reef committed May 7, 2024
1 parent 160e9d1 commit 5104f3e
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion b2/_internal/arg_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 5104f3e

Please sign in to comment.