Commit a1111f34 authored by Aurélien Campéas's avatar Aurélien Campéas
Browse files

cli: signal when cli extensions cannot be loaded

Rather than just crashing ...
This typically happens when there is a discrepancy between
some installed lib version and a required version within
a dependancy.
parent 9596cdc79b23
......@@ -17,7 +17,8 @@ setup(name='tshistory',
'click',
'mock',
'pytest_sa_pg',
'inireader'
'inireader',
'colorama'
],
entry_points={
'console_scripts': [
......
......@@ -3,6 +3,7 @@ from pkg_resources import iter_entry_points
from time import time
import random
from pathlib import Path
from collections import defaultdict
from dateutil import parser
from json import dumps
......@@ -297,8 +298,26 @@ def migrate_dot_6_to_dot_7(db_uri, namespace='tsh'):
snap.reclaim()
for ep in iter_entry_points('tshistory.subcommands'):
tsh.add_command(ep.load())
def register_plugin_subcommands():
errors = defaultdict(set)
for ep in iter_entry_points('tshistory.subcommands'):
try:
cmd = ep.load()
except Exception as e:
errors[str(e)].add(ep.module_name)
continue
tsh.add_command(cmd)
if errors:
from colorama import init, Fore, Style
for error, eplist in errors.items():
print(Fore.YELLOW +
f'impossible to add subcommands from {",".join(eplist)}')
print(Fore.RED +
f'cause: {error}')
register_plugin_subcommands()
if __name__ == '__main__':
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment