Skip to content

Commit

Permalink
Allow verbose/quite level to be specified via config file or env var
Browse files Browse the repository at this point in the history
  • Loading branch information
McSinyx committed Jul 13, 2020
1 parent 8bf5731 commit dba9926
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions src/pip/_internal/cli/parser.py
Expand Up @@ -197,15 +197,20 @@ def _update_defaults(self, defaults):
if option is None:
continue

if option.action in ('store_true', 'store_false', 'count'):
if option.action in ('store_true', 'store_false'):
try:
val = strtobool(val)
except ValueError:
error_msg = invalid_config_error_message(
option.action, key, val
)
self.error(error_msg)

self.error(invalid_store_bool_message(key, val))
elif option.action == 'count':
try:
value = int(val)
except ValueError:
self.error(invalid_count_message(key, val))
if value < 0:
self.error(invalid_count_message(key, val))
else:
val = value
elif option.action == 'append':
val = val.split()
val = [self.check_default(option, key, v) for v in val]
Expand Down Expand Up @@ -253,14 +258,20 @@ def error(self, msg):
self.exit(UNKNOWN_ERROR, "{}\n".format(msg))


def invalid_config_error_message(action, key, val):
def invalid_store_bool_message(key, value):
# type: (str, str) -> str
"""Returns a better error message when invalid configuration option
of action store_false or store_true is provided.
"""
return ("{} is not a valid value for {} option, "
"please specify a boolean value like yes/no, "
"true/false or 1/0 instead.").format(value, key)


def invalid_count_message(key, value):
# type: (str, str) -> str
"""Returns a better error message when invalid configuration option
is provided."""
if action in ('store_true', 'store_false'):
return ("{0} is not a valid value for {1} option, "
"please specify a boolean value like yes/no, "
"true/false or 1/0 instead.").format(val, key)

return ("{0} is not a valid value for {1} option, "
"please specify a numerical value like 1/0 "
"instead.").format(val, key)
of action count is provided.
"""
return ("{} is not a valid value for {} option, "
"please specify a natural number instead.").format(value, key)

0 comments on commit dba9926

Please sign in to comment.