فهرست منبع

Display the usage of subcommands if *.execute() does not exist

python-appimage build previously raised a AttributeError: module 'python_appimage.commands.build' has no attribute 'execute'. This makes users think that its a bug in the program. It would be more intuitive if help / usage is shown instead of AttributeError
Srevin Saju 5 سال پیش
والد
کامیت
ac65e882ee
1فایلهای تغییر یافته به همراه8 افزوده شده و 0 حذف شده
  1. 8 0
      python_appimage/__main__.py

+ 8 - 0
python_appimage/__main__.py

@@ -92,6 +92,14 @@ def main():
     if args.sub_command:
     if args.sub_command:
         module += '.' + args.sub_command
         module += '.' + args.sub_command
     command = import_module(module, package=__package__)
     command = import_module(module, package=__package__)
+
+    # check if the module has a 'execute' subcommand
+    # if not, display the help message
+    if not hasattr(command, 'execute'):
+        locals().get('{}_parser'.format(args.command)).print_help()
+        return
+
+    # execute the command
     command.execute(*command._unpack_args(args))
     command.execute(*command._unpack_args(args))