cli: tabulate warnings for cleaner visual output; add --quick flag for doctor
This commit is contained in:
parent
fd41caa640
commit
ed25fc2eeb
1 changed files with 21 additions and 5 deletions
|
@ -152,11 +152,16 @@ def _modules(all=False):
|
||||||
|
|
||||||
def modules_check(args):
|
def modules_check(args):
|
||||||
verbose: bool = args.verbose
|
verbose: bool = args.verbose
|
||||||
|
quick: bool = args.quick
|
||||||
module: Optional[str] = args.module
|
module: Optional[str] = args.module
|
||||||
vw = '' if verbose else '; pass --verbose to print more information'
|
vw = '' if verbose else '; pass --verbose to print more information'
|
||||||
|
|
||||||
|
from . import common
|
||||||
|
common.QUICK_STATS = quick # dirty, but hopefully OK for cli
|
||||||
|
|
||||||
|
tabulate_warnings()
|
||||||
|
|
||||||
from .util import get_stats, HPIModule
|
from .util import get_stats, HPIModule
|
||||||
from .core_config import config
|
|
||||||
|
|
||||||
mods: Iterable[HPIModule]
|
mods: Iterable[HPIModule]
|
||||||
if module is None:
|
if module is None:
|
||||||
|
@ -185,9 +190,6 @@ def modules_check(args):
|
||||||
stats = get_stats(m)
|
stats = get_stats(m)
|
||||||
if stats is None:
|
if stats is None:
|
||||||
continue
|
continue
|
||||||
from . import common
|
|
||||||
common.QUICK_STATS = True
|
|
||||||
# todo make it a cmdline option..
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
res = stats()
|
res = stats()
|
||||||
|
@ -201,7 +203,7 @@ def modules_check(args):
|
||||||
|
|
||||||
def list_modules(args) -> None:
|
def list_modules(args) -> None:
|
||||||
# todo add a --sort argument?
|
# todo add a --sort argument?
|
||||||
from .core_config import config
|
tabulate_warnings()
|
||||||
|
|
||||||
for mr in _modules(all=args.all):
|
for mr in _modules(all=args.all):
|
||||||
m = mr.name
|
m = mr.name
|
||||||
|
@ -216,6 +218,19 @@ def list_modules(args) -> None:
|
||||||
print(f'{pre} {m:50}{suf}')
|
print(f'{pre} {m:50}{suf}')
|
||||||
|
|
||||||
|
|
||||||
|
def tabulate_warnings():
|
||||||
|
'''
|
||||||
|
Helper to avoid visual noise in hpi modules/doctor
|
||||||
|
'''
|
||||||
|
import warnings
|
||||||
|
orig = warnings.formatwarning
|
||||||
|
def override(*args, **kwargs):
|
||||||
|
res = orig(*args, **kwargs)
|
||||||
|
return ''.join(' ' + x for x in res.splitlines(keepends=True))
|
||||||
|
warnings.formatwarning = override
|
||||||
|
# TODO loggers as well?
|
||||||
|
|
||||||
|
|
||||||
# todo check that it finds private modules too?
|
# todo check that it finds private modules too?
|
||||||
def doctor(args):
|
def doctor(args):
|
||||||
config_check(args)
|
config_check(args)
|
||||||
|
@ -233,6 +248,7 @@ Work in progress, will be used for config management, troubleshooting & introspe
|
||||||
dp = sp.add_parser('doctor', help='Run various checks')
|
dp = sp.add_parser('doctor', help='Run various checks')
|
||||||
dp.add_argument('--verbose', action='store_true', help='Print more diagnosic infomration')
|
dp.add_argument('--verbose', action='store_true', help='Print more diagnosic infomration')
|
||||||
dp.add_argument('--all' , action='store_true', help='List all modules, including disabled')
|
dp.add_argument('--all' , action='store_true', help='List all modules, including disabled')
|
||||||
|
dp.add_argument('--quick' , action='store_true', help='Only run partial checks (first 100 items)')
|
||||||
dp.add_argument('module', nargs='?', type=str , help='Pass to check a specific module')
|
dp.add_argument('module', nargs='?', type=str , help='Pass to check a specific module')
|
||||||
dp.set_defaults(func=doctor)
|
dp.set_defaults(func=doctor)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue