From 6db062ef753c2bbdbe2f47c47348b4dc0bb115c5 Mon Sep 17 00:00:00 2001 From: derAnfaenger Date: Fri, 25 Aug 2017 16:27:52 +0200 Subject: [PATCH] api: Display help on wrong command-line arguments. Fixes #93. --- zulip/zulip/__init__.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/zulip/zulip/__init__.py b/zulip/zulip/__init__.py index 533992d..9359ae8 100644 --- a/zulip/zulip/__init__.py +++ b/zulip/zulip/__init__.py @@ -33,6 +33,7 @@ import optparse import argparse import platform import random +import types from distutils.version import LooseVersion from six.moves.configparser import SafeConfigParser @@ -104,8 +105,15 @@ def _default_client(): # type: () -> str return "ZulipPython/" + __version__ -def add_default_arguments(parser): +def add_default_arguments(parser, patch_error_handling=True): # type: (argparse.ArgumentParser) -> argparse.ArgumentParser + + if patch_error_handling: + def custom_error_handling(self, message): + self.print_help(sys.stderr) + self.exit(2, '{}: error: {}\n'.format(self.prog, message)) + parser.error = types.MethodType(custom_error_handling, parser) + group = parser.add_argument_group('Zulip API configuration') group.add_argument('--site', dest="zulip_site",