From b65ce435c45c91554446e661a7880db589adf392 Mon Sep 17 00:00:00 2001 From: Keegan McAllister Date: Mon, 26 Nov 2012 12:25:35 -0500 Subject: [PATCH] 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) --- examples/get-public-streams | 14 +++----------- examples/list-subscriptions | 14 +++----------- examples/print-messages | 14 +++----------- examples/print-next-message | 14 +++----------- examples/send-message | 20 ++++---------------- examples/subscribe | 19 ++++--------------- examples/unsubscribe | 19 ++++--------------- 7 files changed, 24 insertions(+), 90 deletions(-) diff --git a/examples/get-public-streams b/examples/get-public-streams index 58fa1da..b999e12 100755 --- a/examples/get-public-streams +++ b/examples/get-public-streams @@ -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 """ parser = optparse.OptionParser(usage=usage) -parser.add_option('--site', - dest='site', - default="https://humbughq.com", - action='store') -parser.add_option('--api-key', - dest='api_key', - default=None, - action='store') -parser.add_option('--user', - dest='user', - action='store') +parser.add_option('--site', default='https://humbughq.com') +parser.add_option('--api-key') +parser.add_option('--user') (options, args) = parser.parse_args() sys.path.append(path.join(path.dirname(__file__), '../..')) diff --git a/examples/list-subscriptions b/examples/list-subscriptions index df91516..60c2587 100755 --- a/examples/list-subscriptions +++ b/examples/list-subscriptions @@ -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 """ parser = optparse.OptionParser(usage=usage) -parser.add_option('--site', - dest='site', - default="https://humbughq.com", - action='store') -parser.add_option('--api-key', - dest='api_key', - default=None, - action='store') -parser.add_option('--user', - dest='user', - action='store') +parser.add_option('--site', default='https://humbughq.com') +parser.add_option('--api-key') +parser.add_option('--user') (options, args) = parser.parse_args() sys.path.append(path.join(path.dirname(__file__), '../..')) diff --git a/examples/print-messages b/examples/print-messages index afa2af0..3556824 100755 --- a/examples/print-messages +++ b/examples/print-messages @@ -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 """ parser = optparse.OptionParser(usage=usage) -parser.add_option('--site', - dest='site', - default="https://humbughq.com", - action='store') -parser.add_option('--api-key', - dest='api_key', - default=None, - action='store') -parser.add_option('--user', - dest='user', - action='store') +parser.add_option('--site', default='https://humbughq.com') +parser.add_option('--api-key') +parser.add_option('--user') (options, args) = parser.parse_args() sys.path.append(path.join(path.dirname(__file__), '../..')) diff --git a/examples/print-next-message b/examples/print-next-message index f5e919f..dd3eea4 100755 --- a/examples/print-next-message +++ b/examples/print-next-message @@ -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 """ parser = optparse.OptionParser(usage=usage) -parser.add_option('--site', - dest='site', - default="https://humbughq.com", - action='store') -parser.add_option('--api-key', - dest='api_key', - default=None, - action='store') -parser.add_option('--user', - dest='user', - action='store') +parser.add_option('--site', default='https://humbughq.com') +parser.add_option('--api-key') +parser.add_option('--user') (options, args) = parser.parse_args() sys.path.append(path.join(path.dirname(__file__), '../..')) diff --git a/examples/send-message b/examples/send-message index 97b7b8d..5b3f912 100755 --- a/examples/send-message +++ b/examples/send-message @@ -33,22 +33,10 @@ Example: send-message --type=stream commits Example: send-message --site=https://zephyr.humbughq.com iago@humbughq.com """ parser = optparse.OptionParser(usage=usage) -parser.add_option('--site', - dest='site', - default="https://humbughq.com", - action='store') -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') +parser.add_option('--api-key') +parser.add_option('--site', default='https://humbughq.com') +parser.add_option('--sender', default='othello@humbughq.com') +parser.add_option('--type', default='private') (options, args) = parser.parse_args() if len(args) == 0: diff --git a/examples/subscribe b/examples/subscribe index d776941..d391be1 100755 --- a/examples/subscribe +++ b/examples/subscribe @@ -32,21 +32,10 @@ Ensures the user is subscribed to the listed streams. Example: subscribe --user=tabbott@humbughq.com --site=https://zephyr.humbughq.com """ parser = optparse.OptionParser(usage=usage) -parser.add_option('--site', - dest='site', - default="https://humbughq.com", - action='store') -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') +parser.add_option('--api-key') +parser.add_option('--user') +parser.add_option('--site', default='https://humbughq.com') +parser.add_option('--streams', default='') (options, args) = parser.parse_args() sys.path.append(path.join(path.dirname(__file__), '../..')) diff --git a/examples/unsubscribe b/examples/unsubscribe index 3dd363b..0a1ad83 100755 --- a/examples/unsubscribe +++ b/examples/unsubscribe @@ -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 """ parser = optparse.OptionParser(usage=usage) -parser.add_option('--site', - dest='site', - default="https://humbughq.com", - action='store') -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') +parser.add_option('--api-key') +parser.add_option('--user') +parser.add_option('--site', default='https://humbughq.com') +parser.add_option('--streams', default='') (options, args) = parser.parse_args() sys.path.append(path.join(path.dirname(__file__), '../..'))