From 9088e7fc845d1d0c2cd453b793915a0e6beb1833 Mon Sep 17 00:00:00 2001 From: Srevin Saju Date: Sun, 14 Jun 2020 11:30:53 +0300 Subject: [PATCH 1/2] Automatically show python-appimage usage when no arguments are provided Fixes #21 --- python_appimage/__main__.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/python_appimage/__main__.py b/python_appimage/__main__.py index 9ac2b67..eb8f472 100644 --- a/python_appimage/__main__.py +++ b/python_appimage/__main__.py @@ -82,6 +82,11 @@ def main(): if args.verbosity: logging.getLogger().setLevel(args.verbosity) + # check if no arguments are passed + if args.command is None: + parser.print_help() + return + # Call the requested command module = '.commands.' + args.command if args.sub_command: From ac65e882ee16449136962db54db5bf99e083f6cb Mon Sep 17 00:00:00 2001 From: Srevin Saju Date: Sun, 14 Jun 2020 14:35:37 +0300 Subject: [PATCH 2/2] 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 --- python_appimage/__main__.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/python_appimage/__main__.py b/python_appimage/__main__.py index eb8f472..3173972 100644 --- a/python_appimage/__main__.py +++ b/python_appimage/__main__.py @@ -92,6 +92,14 @@ def main(): if args.sub_command: module += '.' + args.sub_command 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))