api/examples: Simplify optparse use

- The default 'default' is None
- The default 'dest' is the option name, with - replaced with _
- The default 'action' is 'store'

Not coincidentally, these defaults are correct for most of our existing code.

(imported from commit 9c6078bd778324e08e1ca214a97281a7bdce08c2)
This commit is contained in:
Keegan McAllister 2012-11-26 12:25:35 -05:00
parent dd80275354
commit b65ce435c4
7 changed files with 24 additions and 90 deletions

View file

@ -32,17 +32,9 @@ Prints out all the public streams in the realm.
Example: get-public-streams --user=tabbott@humbughq.com --site=https://zephyr.humbughq.com Example: get-public-streams --user=tabbott@humbughq.com --site=https://zephyr.humbughq.com
""" """
parser = optparse.OptionParser(usage=usage) parser = optparse.OptionParser(usage=usage)
parser.add_option('--site', parser.add_option('--site', default='https://humbughq.com')
dest='site', parser.add_option('--api-key')
default="https://humbughq.com", parser.add_option('--user')
action='store')
parser.add_option('--api-key',
dest='api_key',
default=None,
action='store')
parser.add_option('--user',
dest='user',
action='store')
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
sys.path.append(path.join(path.dirname(__file__), '../..')) sys.path.append(path.join(path.dirname(__file__), '../..'))

View file

@ -32,17 +32,9 @@ Prints out a list of the user's subscriptions.
Example: list-subscriptions --user=tabbott@humbughq.com --site=https://zephyr.humbughq.com Example: list-subscriptions --user=tabbott@humbughq.com --site=https://zephyr.humbughq.com
""" """
parser = optparse.OptionParser(usage=usage) parser = optparse.OptionParser(usage=usage)
parser.add_option('--site', parser.add_option('--site', default='https://humbughq.com')
dest='site', parser.add_option('--api-key')
default="https://humbughq.com", parser.add_option('--user')
action='store')
parser.add_option('--api-key',
dest='api_key',
default=None,
action='store')
parser.add_option('--user',
dest='user',
action='store')
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
sys.path.append(path.join(path.dirname(__file__), '../..')) sys.path.append(path.join(path.dirname(__file__), '../..'))

View file

@ -32,17 +32,9 @@ Prints out each message received by the indicated user.
Example: print-messages --user=tabbott@humbughq.com --site=https://zephyr.humbughq.com Example: print-messages --user=tabbott@humbughq.com --site=https://zephyr.humbughq.com
""" """
parser = optparse.OptionParser(usage=usage) parser = optparse.OptionParser(usage=usage)
parser.add_option('--site', parser.add_option('--site', default='https://humbughq.com')
dest='site', parser.add_option('--api-key')
default="https://humbughq.com", parser.add_option('--user')
action='store')
parser.add_option('--api-key',
dest='api_key',
default=None,
action='store')
parser.add_option('--user',
dest='user',
action='store')
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
sys.path.append(path.join(path.dirname(__file__), '../..')) sys.path.append(path.join(path.dirname(__file__), '../..'))

View file

@ -32,17 +32,9 @@ Prints out the next message received by the user.
Example: print-next-messages --user=tabbott@humbughq.com --site=https://zephyr.humbughq.com Example: print-next-messages --user=tabbott@humbughq.com --site=https://zephyr.humbughq.com
""" """
parser = optparse.OptionParser(usage=usage) parser = optparse.OptionParser(usage=usage)
parser.add_option('--site', parser.add_option('--site', default='https://humbughq.com')
dest='site', parser.add_option('--api-key')
default="https://humbughq.com", parser.add_option('--user')
action='store')
parser.add_option('--api-key',
dest='api_key',
default=None,
action='store')
parser.add_option('--user',
dest='user',
action='store')
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
sys.path.append(path.join(path.dirname(__file__), '../..')) sys.path.append(path.join(path.dirname(__file__), '../..'))

View file

@ -33,22 +33,10 @@ Example: send-message --type=stream commits
Example: send-message --site=https://zephyr.humbughq.com iago@humbughq.com Example: send-message --site=https://zephyr.humbughq.com iago@humbughq.com
""" """
parser = optparse.OptionParser(usage=usage) parser = optparse.OptionParser(usage=usage)
parser.add_option('--site', parser.add_option('--api-key')
dest='site', parser.add_option('--site', default='https://humbughq.com')
default="https://humbughq.com", parser.add_option('--sender', default='othello@humbughq.com')
action='store') parser.add_option('--type', default='private')
parser.add_option('--api-key',
dest='api_key',
default=None,
action='store')
parser.add_option('--sender',
dest='sender',
default='othello@humbughq.com',
action='store')
parser.add_option('--type',
dest='type',
default='private',
action='store')
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
if len(args) == 0: if len(args) == 0:

View file

@ -32,21 +32,10 @@ Ensures the user is subscribed to the listed streams.
Example: subscribe --user=tabbott@humbughq.com --site=https://zephyr.humbughq.com Example: subscribe --user=tabbott@humbughq.com --site=https://zephyr.humbughq.com
""" """
parser = optparse.OptionParser(usage=usage) parser = optparse.OptionParser(usage=usage)
parser.add_option('--site', parser.add_option('--api-key')
dest='site', parser.add_option('--user')
default="https://humbughq.com", parser.add_option('--site', default='https://humbughq.com')
action='store') parser.add_option('--streams', default='')
parser.add_option('--api-key',
dest='api_key',
default=None,
action='store')
parser.add_option('--streams',
dest='streams',
default="",
action='store')
parser.add_option('--user',
dest='user',
action='store')
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
sys.path.append(path.join(path.dirname(__file__), '../..')) sys.path.append(path.join(path.dirname(__file__), '../..'))

View file

@ -32,21 +32,10 @@ Ensures the user is not subscribed to the listed streams.
Example: unsubscribe --user=tabbott@humbughq.com --site=https://zephyr.humbughq.com Example: unsubscribe --user=tabbott@humbughq.com --site=https://zephyr.humbughq.com
""" """
parser = optparse.OptionParser(usage=usage) parser = optparse.OptionParser(usage=usage)
parser.add_option('--site', parser.add_option('--api-key')
dest='site', parser.add_option('--user')
default="https://humbughq.com", parser.add_option('--site', default='https://humbughq.com')
action='store') parser.add_option('--streams', default='')
parser.add_option('--api-key',
dest='api_key',
default=None,
action='store')
parser.add_option('--streams',
dest='streams',
default="",
action='store')
parser.add_option('--user',
dest='user',
action='store')
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
sys.path.append(path.join(path.dirname(__file__), '../..')) sys.path.append(path.join(path.dirname(__file__), '../..'))