From eb6da4ae103fd086f11099cd0c463b9c62edd544 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Tue, 8 Mar 2016 16:34:09 -0800 Subject: [PATCH] Improve --color help with argparse metavar --- pre_commit/color.py | 5 ++++- pre_commit/main.py | 16 +++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/pre_commit/color.py b/pre_commit/color.py index a787821c..6fd6d96d 100644 --- a/pre_commit/color.py +++ b/pre_commit/color.py @@ -27,13 +27,16 @@ def format_color(text, color, use_color_setting): return u'{0}{1}{2}'.format(color, text, NORMAL) +COLOR_CHOICES = ('auto', 'always', 'never') + + def use_color(setting): """Choose whether to use color based on the command argument. Args: setting - Either `auto`, `always`, or `never` """ - if setting not in ('auto', 'always', 'never'): + if setting not in COLOR_CHOICES: raise InvalidColorSetting(setting) return ( diff --git a/pre_commit/main.py b/pre_commit/main.py index 58aeea32..128968fe 100644 --- a/pre_commit/main.py +++ b/pre_commit/main.py @@ -79,8 +79,8 @@ def main(argv=None): run_parser.add_argument('hook', nargs='?', help='A single hook-id to run') run_parser.add_argument( '--color', default='auto', type=color.use_color, - help='Whether to use color in output. Choices are `always`, `never`' - ', or `auto`. Defaults to `auto`.', + metavar='{' + ','.join(color.COLOR_CHOICES) + '}', + help='Whether to use color in output. Defaults to `%(default)s`.', ) run_parser.add_argument( '--no-stash', default=False, action='store_true', @@ -91,16 +91,18 @@ def main(argv=None): ) run_parser.add_argument( '--origin', '-o', - help='The origin branch\'s commit_id when using `git push`.', + help="The origin branch's commit_id when using `git push`.", ) run_parser.add_argument( '--source', '-s', - help='The remote branch\'s commit_id when using `git push`.', + help="The remote branch's commit_id when using `git push`.", ) run_parser.add_argument( '--allow-unstaged-config', default=False, action='store_true', - help='Allow an unstaged config to be present. Note that this will ' - 'be stashed before parsing unless --no-stash is specified.' + help=( + 'Allow an unstaged config to be present. Note that this will ' + 'be stashed before parsing unless --no-stash is specified.' + ), ) run_parser.add_argument( '--hook-stage', choices=('commit', 'push'), default='commit', @@ -117,7 +119,7 @@ def main(argv=None): ) help = subparsers.add_parser( - 'help', help='Show help for a specific command.' + 'help', help='Show help for a specific command.', ) help.add_argument('help_cmd', nargs='?', help='Command to show help for.')