core/cli: switch to using click library #155

everything is backwards-compatible with the previous
interface, the only minor changes were to the doctor cmd
which can now accept more than one item to run,
and the --skip-config-check to skip the config_ok
check if the user specifies to

added a test using click.testing.CliRunner (tests
the CLI in an isolated environment), though
additional tests which aren't testing the CLI
itself (parsing arguments or decorator behaviour)
can just call the functions themselves, as they
no longer accept a argparser.Namespace and instead
accept the direct arguments
This commit is contained in:
Sean Breckenridge 2021-04-04 02:06:59 -07:00 committed by GitHub
parent 5ef2775265
commit 349ab78fca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 157 additions and 131 deletions

View file

@ -9,6 +9,9 @@ import sys
from typing import Optional
import warnings
import click
# just bring in the scope of this module for convenience
from warnings import warn
@ -18,16 +21,11 @@ def _colorize(x: str, color: Optional[str]=None) -> str:
if not sys.stdout.isatty():
return x
# click handles importing/initializing colorama if necessary
# on windows it installs it if necessary
# on linux/mac, it manually handles ANSI without needing termcolor
return click.style(x, fg=color)
# I'm not sure about this approach yet, so don't want to introduce a hard dependency yet
try:
import termcolor # type: ignore[import]
import colorama # type: ignore[import]
colorama.init()
return termcolor.colored(x, color)
except:
# todo log something?
return x
def _warn(message: str, *args, color: Optional[str]=None, **kwargs) -> None:
stacklevel = kwargs.get('stacklevel', 1)