Improve --color help with argparse metavar

This commit is contained in:
Anthony Sottile
2016-03-08 16:34:09 -08:00
parent 77a1a29c12
commit eb6da4ae10
2 changed files with 13 additions and 8 deletions

View File

@@ -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 (

View File

@@ -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.')