from optparse import OptionParser

from wgen import WorkloadGen


def main():
    usage = ('spring [-n host:port] -u -p [-b bucket] '
             '[-s size] [-r set ratio] [-o #ops] [w #workers]')

    parser = OptionParser(usage)

    parser.add_option('-n', dest='node', default='127.0.0.1:8091',
                      help='node address (host:port)',
                      metavar='127.0.0.1:8091')
    parser.add_option('-u', dest='username',
                      help='REST username', metavar='Administrator')
    parser.add_option('-p', dest='password',
                      help='REST password', metavar='password')
    parser.add_option('-b', dest='bucket', default='default',
                      help='bucket name', metavar='bucket')

    parser.add_option('-s', dest='size', default=2048, type='int',
                      help='average value size in bytes (2048 by default)',
                      metavar=2048)
    parser.add_option('-r', dest='ratio', type='float', default=1.0,
                      help='fractional ratio of set operations (1.0 by default)',
                      metavar=1.0)
    parser.add_option('-i', dest='items', type='int', default=0,
                      help='number of existing items in dataset (0 by default)',
                      metavar='1000000')
    parser.add_option('-o', dest='ops', type='int', default=float('inf'),
                      help='total number of operations (infinity by default)',
                      metavar='1000')
    parser.add_option('-w', dest='workers', default=1, type="int",
                      help='number of workers (1 by default)', metavar='10')

    options, args = parser.parse_args()

    if not options.username or not options.password:
        parser.error('Missing credentials')

    wg = WorkloadGen(options)
    wg.run()

if __name__ == '__main__':
    main()

@@ -63,20 +63,26 @@
 n%0A%0A%0Adef 
-main
+get_parser
 ():%0A    
@@ -95,13 +95,12 @@
 = ('
-sprin
+%25pro
 g %5B-
@@ -229,16 +229,42 @@
 r(usage)
+%0A    parser.prog = 'sping'
 %0A%0A    pa
@@ -1657,24 +1657,68 @@
 avar='10')%0A%0A
+    return parser%0A%0A%0Adef parse_args(parser):%0A
     options,
@@ -1840,24 +1840,530 @@
 dentials')%0A%0A
+    if not 0 %3C= options.ratio %3C= 1:%0A        parser.error('Invalid ratio. Allowed range is %5B0.0, 1.0%5D.')%0A%0A    if options.ops == float('inf') and options.ratio:%0A        parser.error('Infinite loop allowed only for read-only workloads')%0A%0A    if options.ratio %3C 1 and not options.items:%0A        parser.error('Trying to read indefinite dataset. '%0A                     'Please specify number of items in dataset (-i)')%0A%0A    return options%0A%0A%0Adef main():%0A    parser = get_parser()%0A    options = parse_args(parser)%0A
     wg = Wor

handle some edge cases with invalid user input