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)
This commit is contained in:
parent
de686fc83f
commit
edf6166898
|
@ -66,14 +66,18 @@ def generate_option_group(parser):
|
||||||
help='Provide detailed output.')
|
help='Provide detailed output.')
|
||||||
group.add_option('--client',
|
group.add_option('--client',
|
||||||
action='store',
|
action='store',
|
||||||
default=_default_client(),
|
default=None,
|
||||||
help=optparse.SUPPRESS_HELP)
|
help=optparse.SUPPRESS_HELP)
|
||||||
|
|
||||||
return group
|
return group
|
||||||
|
|
||||||
def init_from_options(options):
|
def init_from_options(options, client=None):
|
||||||
return Client(email=options.email, api_key=options.api_key, config_file=options.config_file,
|
if options.client is not None:
|
||||||
verbose=options.verbose, site=options.site, client=options.client)
|
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):
|
class Client(object):
|
||||||
def __init__(self, email=None, api_key=None, config_file=None,
|
def __init__(self, email=None, api_key=None, config_file=None,
|
||||||
|
|
Loading…
Reference in a new issue