From 710f8042bd8effb1240cf5e8c979e36de4c158cb Mon Sep 17 00:00:00 2001 From: Victor Lin <13424970+victorlin@users.noreply.github.com> Date: Tue, 24 Sep 2024 14:35:18 -0700 Subject: [PATCH] Get subparser formatter class from top-level parser Set a single source of truth. --- augur/__init__.py | 6 ++++-- augur/argparse_.py | 7 +++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/augur/__init__.py b/augur/__init__.py index 00d6e609e..96cf036cc 100644 --- a/augur/__init__.py +++ b/augur/__init__.py @@ -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) diff --git a/augur/argparse_.py b/augur/argparse_.py index 413bf73da..670a35322 100644 --- a/augur/argparse_.py +++ b/augur/argparse_.py @@ -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 @@ -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__