cli: check specific module with doctor; print help on no command
This commit is contained in:
parent
49d25a75ae
commit
5eecd8721d
1 changed files with 13 additions and 7 deletions
|
@ -2,6 +2,7 @@ import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import sys
|
import sys
|
||||||
from subprocess import check_call, run, PIPE
|
from subprocess import check_call, run, PIPE
|
||||||
|
from typing import Optional
|
||||||
import importlib
|
import importlib
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
@ -115,11 +116,16 @@ def config_check(args):
|
||||||
|
|
||||||
|
|
||||||
def modules_check(args):
|
def modules_check(args):
|
||||||
verbose = args.verbose
|
verbose: bool = args.verbose
|
||||||
|
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'
|
||||||
|
|
||||||
|
if module is None:
|
||||||
from .util import get_modules
|
from .util import get_modules
|
||||||
for m in get_modules():
|
modules = get_modules()
|
||||||
|
else:
|
||||||
|
modules = [module]
|
||||||
|
for m in modules:
|
||||||
try:
|
try:
|
||||||
mod = importlib.import_module(m)
|
mod = importlib.import_module(m)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -170,6 +176,7 @@ Work in progress, will be used for config management, troubleshooting & introspe
|
||||||
sp = p.add_subparsers(dest='mode')
|
sp = p.add_subparsers(dest='mode')
|
||||||
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('module', nargs='?', type=str , help='Pass to check a specific module')
|
||||||
dp.set_defaults(func=doctor)
|
dp.set_defaults(func=doctor)
|
||||||
|
|
||||||
cp = sp.add_parser('config', help='Work with configuration')
|
cp = sp.add_parser('config', help='Work with configuration')
|
||||||
|
@ -191,17 +198,16 @@ def main():
|
||||||
p = parser()
|
p = parser()
|
||||||
args = p.parse_args()
|
args = p.parse_args()
|
||||||
|
|
||||||
func = args.func
|
func = getattr(args, 'func', None)
|
||||||
if func is None:
|
if func is None:
|
||||||
# shouldn't happen.. but just in case
|
p.print_help()
|
||||||
p.print_usage()
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
import tempfile
|
import tempfile
|
||||||
with tempfile.TemporaryDirectory() as td:
|
with tempfile.TemporaryDirectory() as td:
|
||||||
# cd into tmp dir to prevent accidental imports..
|
# cd into tmp dir to prevent accidental imports..
|
||||||
os.chdir(str(td))
|
os.chdir(str(td))
|
||||||
args.func(args)
|
func(args)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Add table
Reference in a new issue