Skip to content

Commit

Permalink
Get subparser formatter class from top-level parser
Browse files Browse the repository at this point in the history
Set a single source of truth.
  • Loading branch information
victorlin committed Sep 25, 2024
1 parent 1b110b7 commit 710f804
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 4 additions & 2 deletions augur/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@

def make_parser():
parser = argparse.ArgumentParser(
prog = "augur",
description = "Augur: A bioinformatics toolkit for phylogenetic analysis.")
prog = "augur",
description = "Augur: A bioinformatics toolkit for phylogenetic analysis.",
formatter_class = argparse.ArgumentDefaultsHelpFormatter,
)

add_default_command(parser)
add_version_alias(parser)
Expand Down
7 changes: 3 additions & 4 deletions augur/argparse_.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Custom helpers for the argparse standard library.
"""
import argparse
from argparse import Action, ArgumentDefaultsHelpFormatter
from argparse import Action


# Include this in an argument help string to suppress the automatic appending
Expand Down Expand Up @@ -58,9 +58,8 @@ def register_commands(parser: argparse.ArgumentParser, commands, command_attribu
if command_attribute:
subparser.set_defaults(**{command_attribute: command})

# Use the same formatting class for every command for consistency.
# Set here to avoid repeating it in every command's register_parser().
subparser.formatter_class = ArgumentDefaultsHelpFormatter
# Ensure all subparsers format like the top-level parser
subparser.formatter_class = parser.formatter_class

if not subparser.description and command.__doc__:
subparser.description = command.__doc__
Expand Down

0 comments on commit 710f804

Please sign in to comment.