api: Set required fields in the examples.

Now all the API examples have their corresponding arguments set as
required when they have to be present for the example to run.
This commit is contained in:
Yago González 2018-05-14 21:15:16 +02:00 committed by Tim Abbott
parent cb171409c5
commit 285464a367
6 changed files with 18 additions and 17 deletions

View file

@ -37,10 +37,10 @@ Specify your Zulip API credentials and server in a ~/.zuliprc file or using the
import zulip
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')
parser.add_argument('--new-email', required=True)
parser.add_argument('--new-password', required=True)
parser.add_argument('--new-full-name', required=True)
parser.add_argument('--new-short-name', required=True)
options = parser.parse_args()
client = zulip.init_from_options(options)

View file

@ -24,9 +24,10 @@
from __future__ import print_function
import argparse
usage = """edit-message [options] --message=<msg_id> --subject=<new subject> --content=<new content>
usage = """edit-message [options] --message-id=<msg_id> --subject=<new subject> --content=<new content>
Edits a message that you sent
Edits a message that you sent. At least one of --subject or --content must be
specified.
Example: edit-message --message-id="348135" --subject="my subject" --content="test message"
@ -36,7 +37,7 @@ Specify your Zulip API credentials and server in a ~/.zuliprc file or using the
import zulip
parser = zulip.add_default_arguments(argparse.ArgumentParser(usage=usage))
parser.add_argument('--message-id', type=int)
parser.add_argument('--message-id', type=int, required=True)
parser.add_argument('--subject', default="")
parser.add_argument('--content', default="")
options = parser.parse_args()

View file

@ -32,7 +32,7 @@ Get presence data for another user.
import zulip
parser = zulip.add_default_arguments(argparse.ArgumentParser(usage=usage))
parser.add_argument('--email')
parser.add_argument('--email', required=True)
options = parser.parse_args()
client = zulip.init_from_options(options)

View file

@ -37,7 +37,7 @@ Specify your Zulip API credentials and server in a ~/.zuliprc file or using the
import zulip
parser = zulip.add_default_arguments(argparse.ArgumentParser(usage=usage))
parser.add_argument('--count', default=100)
parser.add_argument('--count', default=100, type=int)
options = parser.parse_args()
client = zulip.init_from_options(options)

View file

@ -34,18 +34,18 @@ Example: send-message --type=stream commits --subject="my subject" --message="te
Example: send-message user1@example.com user2@example.com
"""
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('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)
message_data = {
"type": options.type,
"content": options.message,
"subject": options.subject,
"to": options.recipients,
'type': options.type,
'content': options.message,
'subject': options.subject,
'to': options.recipients,
}
print(client.send_message(message_data))

View file

@ -42,7 +42,7 @@ If no --file-path is specified, a placeholder text file will be used instead.
"""
parser = zulip.add_default_arguments(argparse.ArgumentParser(usage=usage))
parser.add_argument('--file-path')
parser.add_argument('--file-path', required=True)
options = parser.parse_args()
client = zulip.init_from_options(options)