Skip to content

Commit eb6da4a

Browse files
committed
Improve --color help with argparse metavar
1 parent 77a1a29 commit eb6da4a

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

pre_commit/color.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,16 @@ def format_color(text, color, use_color_setting):
2727
return u'{0}{1}{2}'.format(color, text, NORMAL)
2828

2929

30+
COLOR_CHOICES = ('auto', 'always', 'never')
31+
32+
3033
def use_color(setting):
3134
"""Choose whether to use color based on the command argument.
3235
3336
Args:
3437
setting - Either `auto`, `always`, or `never`
3538
"""
36-
if setting not in ('auto', 'always', 'never'):
39+
if setting not in COLOR_CHOICES:
3740
raise InvalidColorSetting(setting)
3841

3942
return (

pre_commit/main.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ def main(argv=None):
7979
run_parser.add_argument('hook', nargs='?', help='A single hook-id to run')
8080
run_parser.add_argument(
8181
'--color', default='auto', type=color.use_color,
82-
help='Whether to use color in output. Choices are `always`, `never`'
83-
', or `auto`. Defaults to `auto`.',
82+
metavar='{' + ','.join(color.COLOR_CHOICES) + '}',
83+
help='Whether to use color in output. Defaults to `%(default)s`.',
8484
)
8585
run_parser.add_argument(
8686
'--no-stash', default=False, action='store_true',
@@ -91,16 +91,18 @@ def main(argv=None):
9191
)
9292
run_parser.add_argument(
9393
'--origin', '-o',
94-
help='The origin branch\'s commit_id when using `git push`.',
94+
help="The origin branch's commit_id when using `git push`.",
9595
)
9696
run_parser.add_argument(
9797
'--source', '-s',
98-
help='The remote branch\'s commit_id when using `git push`.',
98+
help="The remote branch's commit_id when using `git push`.",
9999
)
100100
run_parser.add_argument(
101101
'--allow-unstaged-config', default=False, action='store_true',
102-
help='Allow an unstaged config to be present. Note that this will '
103-
'be stashed before parsing unless --no-stash is specified.'
102+
help=(
103+
'Allow an unstaged config to be present. Note that this will '
104+
'be stashed before parsing unless --no-stash is specified.'
105+
),
104106
)
105107
run_parser.add_argument(
106108
'--hook-stage', choices=('commit', 'push'), default='commit',
@@ -117,7 +119,7 @@ def main(argv=None):
117119
)
118120

119121
help = subparsers.add_parser(
120-
'help', help='Show help for a specific command.'
122+
'help', help='Show help for a specific command.',
121123
)
122124
help.add_argument('help_cmd', nargs='?', help='Command to show help for.')
123125

0 commit comments

Comments
 (0)