Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display short description from docstring instead of params in usage #290

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
Loading