Make host:port an option, and convert list-builders to subcommand. master
authorTim Potter <tpot@hp.com>
Mon, 28 Apr 2008 07:59:55 +0000 (17:59 +1000)
committerTim Potter <tpot@hp.com>
Mon, 28 Apr 2008 07:59:55 +0000 (17:59 +1000)
bbc

diff --git a/bbc b/bbc
index 682b53b..212fbed 100755 (executable)
--- a/bbc
+++ b/bbc
@@ -8,26 +8,22 @@ import sys
 from twisted.python import usage
 from twisted.internet import reactor
 
-OPT_LIST_BUILDERS = 'list-builders'
+CMD_LIST_BUILDERS = 'list-builders'
 
 OPT_USER = 'user'
 OPT_PASSWORD = 'password'
+OPT_HOST = 'host'
 
 class Options(usage.Options):
 
-    optFlags = [
-        [OPT_LIST_BUILDERS, 'b', 'List available builders'],
+    subCommands = [
+        [CMD_LIST_BUILDERS, None, usage.Options, 'List available builders'],
     ]
 
     optParameters = [
         [OPT_USER, 'u', None, 'Username to connect as'],
         [OPT_PASSWORD, 'p', None, 'Password to connect with'],
-    ]
-
-    def parseArgs(self, server):
-        host, port = server.split(':')
-        self['host'] = host
-        self['port'] = int(port)
+        [OPT_HOST, 'h', None, 'Hostname and port to connect to']]
 
 def list_builders(connect_result, client):
     """List builders by name."""
@@ -64,22 +60,28 @@ if __name__ == '__main__':
         print options
         sys.exit(1)
 
+    if options[OPT_HOST] is None:
+        print '%s: must specify host:port' % sys.argv[0]
+        print options
+        sys.exit(1)
+
+    host, port = options[OPT_HOST].split(':')
+    port = int(port)
+
     # Make buildbot connection
 
     from bbclient import BuildbotClient
 
     client = BuildbotClient()
     
-    d = client.connect(
-        options['host'], options['port'], 
-        options[OPT_USER], options[OPT_PASSWORD])
+    d = client.connect(host, port, options[OPT_USER], options[OPT_PASSWORD])
 
     # Execute commands
 
-    if options[OPT_LIST_BUILDERS] == 1:
+    if options.subCommand == CMD_LIST_BUILDERS:
         d.addCallback(list_builders, client)
     else:
-        print '%s: Must specify an operation to perform!' % sys.argv[0]
+        print '%s: Must specify a command!' % sys.argv[0]
         print options
         sys.exit(1)