summaryrefslogtreecommitdiff
path: root/example.py
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@sonymobile.com>2014-04-11 16:59:50 +0900
committerDavid Pursehouse <david.pursehouse@sonymobile.com>2014-04-11 17:02:18 +0900
commit39f7906b5774243e6fe9fb622dcec37d0cef3ca0 (patch)
treefa90e56178a3cd899a1470144a646b2bc7e6b0a8 /example.py
parenta76db4cfc83d4cf7a52d045e4df82ec8b1e3f562 (diff)
downloadpygerrit-39f7906b5774243e6fe9fb622dcec37d0cef3ca0.tar.gz
Fix up usage of argparse in examples
Since a76db4cfc83d4cf7a52d045e4df82ec8b1e3f562 it is broken. - Use ArgumentDefaultsHelpFormatter to automatically show default values for the options. - Remove hard-coded 'default' information from help texts. - Add a metavar for the ssh event timeout option. - Integer arguments must now be specified as `int` rather than `'int'` with quotation marks. - Fix calls to `parser.parse_args`, which now returns a single value rather than a tuple. Change-Id: If5cf4e2d1f4014a60f7a7634d43df12b788bc7b4
Diffstat (limited to 'example.py')
-rwxr-xr-xexample.py22
1 files changed, 12 insertions, 10 deletions
diff --git a/example.py b/example.py
index a5b7be8..99fe940 100755
--- a/example.py
+++ b/example.py
@@ -25,8 +25,8 @@
""" Example of using the Gerrit client class. """
-import logging
import argparse
+import logging
import sys
from threading import Event
import time
@@ -38,22 +38,24 @@ from pygerrit.events import ErrorEvent
def _main():
descr = 'Send request using Gerrit ssh API'
- parser = argparse.ArgumentParser(description=descr)
+ parser = argparse.ArgumentParser(
+ description=descr,
+ formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('-g', '--gerrit-hostname', dest='hostname',
default='review',
- help='gerrit server hostname (default: %default)')
+ help='gerrit server hostname')
parser.add_argument('-p', '--port', dest='port',
- type='int', default=29418,
- help='port number (default: %default)')
+ type=int, default=29418,
+ help='port number')
parser.add_argument('-u', '--username', dest='username',
help='username')
parser.add_argument('-b', '--blocking', dest='blocking',
action='store_true',
- help='block on event get (default: False)')
+ help='block on event get')
parser.add_argument('-t', '--timeout', dest='timeout',
- default=None, type='int',
- help='timeout (seconds) for blocking event get '
- '(default: None)')
+ default=None, type=int,
+ metavar='SECONDS',
+ help='timeout for blocking event get')
parser.add_argument('-v', '--verbose', dest='verbose',
action='store_true',
help='enable verbose (debug) logging')
@@ -61,7 +63,7 @@ def _main():
action='store_true',
help='do not exit when an error event is received')
- (options, _args) = parser.parse_args()
+ options = parser.parse_args()
if options.timeout and not options.blocking:
parser.error('Can only use --timeout with --blocking')