Commit 377ad479 authored by Jakub Ružička's avatar Jakub Ružička
Browse files

CLI: don't supress command module errors

Check if a command module exists before importing and show all errors
during import instead of misleading

    Invalid apkg command: foo

Fixes: #46
parent 5e059383
Pipeline #80359 passed with stage
in 1 minute and 51 seconds
......@@ -23,6 +23,7 @@ Options:
# A script for updating the __doc__ string here that is run
# when dev adds a new command might be a decent compromise.
import importlib
import sys
from docopt import docopt
......@@ -91,11 +92,11 @@ def run_command(cargs):
command = cargs[0]
modname = 'apkg.commands.%s' % cmd2mod(command)
mod = __import__(modname, fromlist=[''])
# py35 compat: use ModuleNotFoundError once py3.5 support is dropped
except ImportError:
spec = importlib.util.find_spec(modname)
if not spec:
raise ex.InvalidApkgCommand(command=command)
# import command module
mod = __import__(modname, fromlist=[''])
return mod.run_command(cargs)
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