From edf61668980e9623e952d7a36baf7eec658f7f56 Mon Sep 17 00:00:00 2001 From: Luke Faraone Date: Fri, 6 Dec 2013 17:34:20 -0500 Subject: [PATCH] api: Let users of init_from_options specify a default client. This way command-line scripts that use our `optparse` populator can still specify a custom client without munging their `parser` object. (imported from commit df8d28a46a4d4574523b106030dbfed2d9ac931e) --- zulip/__init__.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/zulip/__init__.py b/zulip/__init__.py index 24b7fdf..e2e4529 100644 --- a/zulip/__init__.py +++ b/zulip/__init__.py @@ -66,14 +66,18 @@ def generate_option_group(parser): help='Provide detailed output.') group.add_option('--client', action='store', - default=_default_client(), + default=None, help=optparse.SUPPRESS_HELP) - return group -def init_from_options(options): - return Client(email=options.email, api_key=options.api_key, config_file=options.config_file, - verbose=options.verbose, site=options.site, client=options.client) +def init_from_options(options, client=None): + if options.client is not None: + client = options.client + elif client is None: + client = _default_client() + return Client(email=options.email, api_key=options.api_key, + config_file=options.config_file, verbose=options.verbose, + site=options.site, client=client) class Client(object): def __init__(self, email=None, api_key=None, config_file=None,