def _parse_boolean(self, string):
"""Parse string representing a boolean into Python bool type.
Supported values match `configparser.ConfigParser.getboolean`.
"""
trues = ['1', 'yes', 'true', 'on']
falses = ['0', 'no', 'false', 'off']
string_lower = string.lower()
if string_lower in trues:
return True
elif string_lower in falses:
return False
else:
import itertools
import click
msg = (
"Error: unrecognized value for --%s flag: %s\n"
"Supported values (case-insensitive): %s" %
(self.cli_name, string,
', '.join(itertools.chain(trues, falses)))
)
click.secho(msg, err=True, fg='red', bold=True)
ctx = click.get_current_context()
ctx.exit(1)
评论列表
文章目录