Merge pull request #2288 from dnephin/warning_about_vars
Add console color to warnings and errors so they are more obvious
This commit is contained in:
commit
c439e056a0
8 changed files with 111 additions and 17 deletions
|
|
@ -28,6 +28,7 @@ from .command import project_from_options
|
|||
from .docopt_command import DocoptCommand
|
||||
from .docopt_command import NoSuchCommand
|
||||
from .errors import UserError
|
||||
from .formatter import ConsoleWarningFormatter
|
||||
from .formatter import Formatter
|
||||
from .log_printer import LogPrinter
|
||||
from .utils import get_version_info
|
||||
|
|
@ -41,7 +42,7 @@ log = logging.getLogger(__name__)
|
|||
console_handler = logging.StreamHandler(sys.stderr)
|
||||
|
||||
INSECURE_SSL_WARNING = """
|
||||
Warning: --allow-insecure-ssl is deprecated and has no effect.
|
||||
--allow-insecure-ssl is deprecated and has no effect.
|
||||
It will be removed in a future version of Compose.
|
||||
"""
|
||||
|
||||
|
|
@ -58,9 +59,8 @@ def main():
|
|||
log.error(e.msg)
|
||||
sys.exit(1)
|
||||
except NoSuchCommand as e:
|
||||
log.error("No such command: %s", e.command)
|
||||
log.error("")
|
||||
log.error("\n".join(parse_doc_section("commands:", getdoc(e.supercommand))))
|
||||
commands = "\n".join(parse_doc_section("commands:", getdoc(e.supercommand)))
|
||||
log.error("No such command: %s\n\n%s", e.command, commands)
|
||||
sys.exit(1)
|
||||
except APIError as e:
|
||||
log.error(e.explanation)
|
||||
|
|
@ -91,13 +91,18 @@ def setup_logging():
|
|||
logging.getLogger("requests").propagate = False
|
||||
|
||||
|
||||
def setup_console_handler(verbose):
|
||||
if verbose:
|
||||
console_handler.setFormatter(logging.Formatter('%(name)s.%(funcName)s: %(message)s'))
|
||||
console_handler.setLevel(logging.DEBUG)
|
||||
def setup_console_handler(handler, verbose):
|
||||
if handler.stream.isatty():
|
||||
format_class = ConsoleWarningFormatter
|
||||
else:
|
||||
console_handler.setFormatter(logging.Formatter())
|
||||
console_handler.setLevel(logging.INFO)
|
||||
format_class = logging.Formatter
|
||||
|
||||
if verbose:
|
||||
handler.setFormatter(format_class('%(name)s.%(funcName)s: %(message)s'))
|
||||
handler.setLevel(logging.DEBUG)
|
||||
else:
|
||||
handler.setFormatter(format_class())
|
||||
handler.setLevel(logging.INFO)
|
||||
|
||||
|
||||
# stolen from docopt master
|
||||
|
|
@ -153,7 +158,7 @@ class TopLevelCommand(DocoptCommand):
|
|||
return options
|
||||
|
||||
def perform_command(self, options, handler, command_options):
|
||||
setup_console_handler(options.get('--verbose'))
|
||||
setup_console_handler(console_handler, options.get('--verbose'))
|
||||
|
||||
if options['COMMAND'] in ('help', 'version'):
|
||||
# Skip looking up the compose file.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue