zulip/examples: Use argparse-based zulip.add_default_arguments.
MODIFY
zulip/examples/create-user
zulip/examples/create-user
from __future__ import print_function
import sys
from os import path
-import optparse
+import argparse
usage = """create-user --new-email=<email address> --new-password=<password> --new-full-name=<full name> --new-short-name=<short name> [options]
@@ -37,13 +37,12 @@ Example: create-user --site=http://localhost:9991 --user=rwbarton@example.com --
sys.path.append(path.join(path.dirname(__file__), '..'))
import zulip
-parser = optparse.OptionParser(usage=usage)
-parser.add_option_group(zulip.generate_option_group(parser))
-parser.add_option('--new-email')
-parser.add_option('--new-password')
-parser.add_option('--new-full-name')
-parser.add_option('--new-short-name')
-(options, args) = parser.parse_args()
+parser = zulip.add_default_arguments(argparse.ArgumentParser(usage=usage))
+parser.add_argument('--new-email')
+parser.add_argument('--new-password')
+parser.add_argument('--new-full-name')
+parser.add_argument('--new-short-name')
+options = parser.parse_args()
client = zulip.init_from_options(options)

MODIFY
zulip/examples/edit-message
zulip/examples/edit-message
from __future__ import print_function
import sys
import os
-import optparse
+import argparse
usage = """edit-message [options] --message=<msg_id> --subject=<new subject> --content=<new content> --user=<sender's email address> --api-key=<sender's api key>
@@ -38,12 +38,11 @@ You can omit --user and --api-key arguments if you have a properly set up ~/.zul
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
import zulip
-parser = optparse.OptionParser(usage=usage)
-parser.add_option('--message-id', default="")
-parser.add_option('--subject', default="")
-parser.add_option('--content', default="")
-parser.add_option_group(zulip.generate_option_group(parser))
-(options, args) = parser.parse_args()
+parser = zulip.add_default_arguments(argparse.ArgumentParser(usage=usage))
+parser.add_argument('--message-id', default="")
+parser.add_argument('--subject', default="")
+parser.add_argument('--content', default="")
+options = parser.parse_args()
client = zulip.init_from_options(options)

MODIFY
zulip/examples/get-presence
zulip/examples/get-presence
from __future__ import print_function
import sys
from os import path
-import optparse
+import argparse
usage = """get-presence --email=<email address> [options]
@@ -34,10 +34,9 @@ Get presence data for another user.
sys.path.append(path.join(path.dirname(__file__), '..'))
import zulip
-parser = optparse.OptionParser(usage=usage)
-parser.add_option_group(zulip.generate_option_group(parser))
-parser.add_option('--email')
-(options, args) = parser.parse_args()
+parser = zulip.add_default_arguments(argparse.ArgumentParser(usage=usage))
+parser.add_argument('--email')
+options = parser.parse_args()
client = zulip.init_from_options(options)

MODIFY
zulip/examples/get-public-streams
zulip/examples/get-public-streams
from __future__ import print_function
import sys
import os
-import optparse
+import argparse
usage = """get-public-streams --user=<bot's email address> --api-key=<bot's api key> [options]
@@ -38,9 +38,8 @@ You can omit --user and --api-key arguments if you have a properly set up ~/.zul
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
import zulip
-parser = optparse.OptionParser(usage=usage)
-parser.add_option_group(zulip.generate_option_group(parser))
-(options, args) = parser.parse_args()
+parser = zulip.add_default_arguments(argparse.ArgumentParser(usage=usage))
+options = parser.parse_args()
client = zulip.init_from_options(options)

MODIFY
zulip/examples/list-members
zulip/examples/list-members
from __future__ import print_function
import sys
import os
-import optparse
+import argparse
usage = """list-members --user=<bot's email address> --api-key=<bot's api key> [options]
@@ -36,9 +36,8 @@ You can omit --user and --api-key arguments if you have a properly set up ~/.zul
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
import zulip
-parser = optparse.OptionParser(usage=usage)
-parser.add_option_group(zulip.generate_option_group(parser))
-(options, args) = parser.parse_args()
+parser = zulip.add_default_arguments(argparse.ArgumentParser(usage=usage))
+options = parser.parse_args()
client = zulip.init_from_options(options)

MODIFY
zulip/examples/list-subscriptions
zulip/examples/list-subscriptions
from __future__ import print_function
import sys
import os
-import optparse
+import argparse
usage = """list-subscriptions --user=<bot's email address> --api-key=<bot's api key> [options]
@@ -37,9 +37,8 @@ You can omit --user and --api-key arguments if you have a properly set up ~/.zul
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
import zulip
-parser = optparse.OptionParser(usage=usage)
-parser.add_option_group(zulip.generate_option_group(parser))
-(options, args) = parser.parse_args()
+parser = zulip.add_default_arguments(argparse.ArgumentParser(usage=usage))
+options = parser.parse_args()
client = zulip.init_from_options(options)

MODIFY
zulip/examples/print-events
zulip/examples/print-events
from __future__ import print_function
import sys
import os
-import optparse
+import argparse
from typing import Any, Dict
@@ -39,9 +39,8 @@ You can omit --user and --api-key arguments if you have a properly set up ~/.zul
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
import zulip
-parser = optparse.OptionParser(usage=usage)
-parser.add_option_group(zulip.generate_option_group(parser))
-(options, args) = parser.parse_args()
+parser = zulip.add_default_arguments(argparse.ArgumentParser(usage=usage))
+options = parser.parse_args()
client = zulip.init_from_options(options)

MODIFY
zulip/examples/print-messages
zulip/examples/print-messages
from __future__ import print_function
import sys
import os
-import optparse
+import argparse
from typing import Any, Dict
@@ -39,9 +39,8 @@ You can omit --user and --api-key arguments if you have a properly set up ~/.zul
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
import zulip
-parser = optparse.OptionParser(usage=usage)
-parser.add_option_group(zulip.generate_option_group(parser))
-(options, args) = parser.parse_args()
+parser = zulip.add_default_arguments(argparse.ArgumentParser(usage=usage))
+options = parser.parse_args()
client = zulip.init_from_options(options)

MODIFY
zulip/examples/recent-messages
zulip/examples/recent-messages
@@ -25,7 +25,7 @@ from __future__ import print_function
import sys
import os
import json
-import optparse
+import argparse
usage = """recent-messages [options] --count=<no. of previous messages> --user=<sender's email address> --api-key=<sender's api key>
@@ -38,10 +38,9 @@ You can omit --user and --api-key arguments if you have a properly set up ~/.zul
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
import zulip
-parser = optparse.OptionParser(usage=usage)
-parser.add_option('--count', default=100)
-parser.add_option_group(zulip.generate_option_group(parser))
-(options, args) = parser.parse_args()
+parser = zulip.add_default_arguments(argparse.ArgumentParser(usage=usage))
+parser.add_argument('--count', default=100)
+options = parser.parse_args()
client = zulip.init_from_options(options)

MODIFY
zulip/examples/send-message
zulip/examples/send-message
from __future__ import print_function
import sys
import os
-import optparse
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
+import argparse
+
import zulip
usage = """send-message --user=<bot's email address> --api-key=<bot's api key> [options] <recipients>
@@ -37,15 +38,12 @@ Example: send-message --user=your-bot@example.com --api-key=a0b1c2d3e4f5a6b7c8d9
You can omit --user and --api-key arguments if you have a properly set up ~/.zuliprc
"""
-parser = optparse.OptionParser(usage=usage)
-parser.add_option('--subject', default="test")
-parser.add_option('--message', default="test message")
-parser.add_option('--type', default='private')
-parser.add_option_group(zulip.generate_option_group(parser))
-(options, args) = parser.parse_args()
-
-if len(args) == 0:
- parser.error("You must specify recipients")
+parser = zulip.add_default_arguments(argparse.ArgumentParser(usage=usage))
+parser.add_argument('recipients', nargs='*')
+parser.add_argument('--subject', default="test")
+parser.add_argument('--message', default="test message")
+parser.add_argument('--type', default='private')
+options = parser.parse_args()
client = zulip.init_from_options(options)
@@ -53,6 +51,6 @@ message_data = {
"type": options.type,
"content": options.message,
"subject": options.subject,
- "to": args,
+ "to": options.recipients,
}
print(client.send_message(message_data))

MODIFY
zulip/examples/subscribe
zulip/examples/subscribe
from __future__ import print_function
import sys
import os
-import optparse
+import argparse
usage = """subscribe --user=<bot's email address> --api-key=<bot's api key> [options] --streams=<streams>
@@ -38,10 +38,9 @@ You can omit --user and --api-key arguments if you have a properly set up ~/.zul
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
import zulip
-parser = optparse.OptionParser(usage=usage)
-parser.add_option_group(zulip.generate_option_group(parser))
-parser.add_option('--streams', default='')
-(options, args) = parser.parse_args()
+parser = zulip.add_default_arguments(argparse.ArgumentParser(usage=usage))
+parser.add_argument('--streams', default='')
+options = parser.parse_args()
client = zulip.init_from_options(options)

MODIFY
zulip/examples/unsubscribe
zulip/examples/unsubscribe
from __future__ import print_function
import sys
import os
-import optparse
+import argparse
usage = """unsubscribe --user=<bot's email address> --api-key=<bot's api key> [options] --streams=<streams>
@@ -38,10 +38,9 @@ You can omit --user and --api-key arguments if you have a properly set up ~/.zul
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
import zulip
-parser = optparse.OptionParser(usage=usage)
-parser.add_option_group(zulip.generate_option_group(parser))
-parser.add_option('--streams', default='')
-(options, args) = parser.parse_args()
+parser = zulip.add_default_arguments(argparse.ArgumentParser(usage=usage))
+parser.add_argument('--streams', default='')
+options = parser.parse_args()
client = zulip.init_from_options(options)

MODIFY
zulip/examples/upload-file
zulip/examples/upload-file
from __future__ import print_function
import importlib
-import optparse
import sys
+import argparse
from six.moves import StringIO as _StringIO
sys.path.insert(0, './api')
@@ -44,10 +44,9 @@ You can omit --user and --api-key arguments if you have a properly set up ~/.zul
If no --file-path is specified, a placeholder text file will be used instead.
"""
-parser = optparse.OptionParser(usage=usage)
-parser.add_option('--file-path')
-parser.add_option_group(zulip.generate_option_group(parser))
-(options, args) = parser.parse_args()
+parser = zulip.add_default_arguments(argparse.ArgumentParser(usage=usage))
+parser.add_argument('--file-path')
+options = parser.parse_args()
client = zulip.init_from_options(options)

zulip/examples: Use argparse-based zulip.add_default_arguments.