mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-13 12:30:08 -06:00
Improve --color help with argparse metavar
This commit is contained in:
@@ -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 (
|
||||
|
||||
@@ -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.')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user