mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Improve --color help with argparse metavar
This commit is contained in:
parent
77a1a29c12
commit
eb6da4ae10
2 changed files with 13 additions and 8 deletions
|
|
@ -27,13 +27,16 @@ def format_color(text, color, use_color_setting):
|
||||||
return u'{0}{1}{2}'.format(color, text, NORMAL)
|
return u'{0}{1}{2}'.format(color, text, NORMAL)
|
||||||
|
|
||||||
|
|
||||||
|
COLOR_CHOICES = ('auto', 'always', 'never')
|
||||||
|
|
||||||
|
|
||||||
def use_color(setting):
|
def use_color(setting):
|
||||||
"""Choose whether to use color based on the command argument.
|
"""Choose whether to use color based on the command argument.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
setting - Either `auto`, `always`, or `never`
|
setting - Either `auto`, `always`, or `never`
|
||||||
"""
|
"""
|
||||||
if setting not in ('auto', 'always', 'never'):
|
if setting not in COLOR_CHOICES:
|
||||||
raise InvalidColorSetting(setting)
|
raise InvalidColorSetting(setting)
|
||||||
|
|
||||||
return (
|
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('hook', nargs='?', help='A single hook-id to run')
|
||||||
run_parser.add_argument(
|
run_parser.add_argument(
|
||||||
'--color', default='auto', type=color.use_color,
|
'--color', default='auto', type=color.use_color,
|
||||||
help='Whether to use color in output. Choices are `always`, `never`'
|
metavar='{' + ','.join(color.COLOR_CHOICES) + '}',
|
||||||
', or `auto`. Defaults to `auto`.',
|
help='Whether to use color in output. Defaults to `%(default)s`.',
|
||||||
)
|
)
|
||||||
run_parser.add_argument(
|
run_parser.add_argument(
|
||||||
'--no-stash', default=False, action='store_true',
|
'--no-stash', default=False, action='store_true',
|
||||||
|
|
@ -91,16 +91,18 @@ def main(argv=None):
|
||||||
)
|
)
|
||||||
run_parser.add_argument(
|
run_parser.add_argument(
|
||||||
'--origin', '-o',
|
'--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(
|
run_parser.add_argument(
|
||||||
'--source', '-s',
|
'--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(
|
run_parser.add_argument(
|
||||||
'--allow-unstaged-config', default=False, action='store_true',
|
'--allow-unstaged-config', default=False, action='store_true',
|
||||||
help='Allow an unstaged config to be present. Note that this will '
|
help=(
|
||||||
'be stashed before parsing unless --no-stash is specified.'
|
'Allow an unstaged config to be present. Note that this will '
|
||||||
|
'be stashed before parsing unless --no-stash is specified.'
|
||||||
|
),
|
||||||
)
|
)
|
||||||
run_parser.add_argument(
|
run_parser.add_argument(
|
||||||
'--hook-stage', choices=('commit', 'push'), default='commit',
|
'--hook-stage', choices=('commit', 'push'), default='commit',
|
||||||
|
|
@ -117,7 +119,7 @@ def main(argv=None):
|
||||||
)
|
)
|
||||||
|
|
||||||
help = subparsers.add_parser(
|
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.')
|
help.add_argument('help_cmd', nargs='?', help='Command to show help for.')
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue