Skip to content

Commit

Permalink
workaround to hide command aliases in usage
Browse files Browse the repository at this point in the history
  • Loading branch information
adal-chiriliuc-reef committed Apr 26, 2024
1 parent 3fd6eed commit b17e93c
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions b2/_internal/arg_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,31 @@ def print_help(self, *args, show_all: bool = False, **kwargs):
):
super().print_help(*args, **kwargs)

def format_usage(self):
# TODO We don't want to list underscore aliases subcommands in the usage.
# Unfortunately the only way found was to temporarily remove the aliases,
# print the usage and then restore the aliases since the formatting is deep
# inside the Python argparse module.
# We restore the original dictionary which we don't modify, just in case
# someone else has taken a reference to it.
subparsers_action = None
original_choices = None
if self._subparsers is not None:
for action in self._subparsers._actions:
if isinstance(action, argparse._SubParsersAction):
subparsers_action = action
original_choices = action.choices
action.choices = {
key: choice
for key, choice in action.choices.items() if "_" not in key
}
# only one subparser supported
break
usage = super().format_usage()
if subparsers_action is not None:
subparsers_action.choices = original_choices
return usage


SUPPORT_CAMEL_CASE_ARGUMENTS = False

Expand Down

0 comments on commit b17e93c

Please sign in to comment.