#!/usr/bin/python
#
# Convert a test specification to command-line options

import pscheduler
import validate

spec = pscheduler.json_load(exit_on_error=True, max_schema=3)

if type(spec) != dict:
    pscheduler.fail("Invalid JSON for this operation")

valid, message = validate.spec_is_valid(spec)
if not valid:
    pscheduler.fail(message)

strings = []
bools = []


if spec.get('schema', 1) == 3:
    spec_properties = validate.SPEC_SCHEMA['local']['throughput_v3']['properties']
elif spec.get('schema', 1) == 2:
    spec_properties = validate.SPEC_SCHEMA['local']['throughput_v2']['properties']
else:
    spec_properties = validate.SPEC_SCHEMA['local']['throughput_v1']['properties']

for item in spec_properties.keys():
    if item == 'schema': continue
    if spec_properties[item].has_key("$ref") and "Boolean" in spec_properties[item]['$ref']:
        bools.append( (item, item) )
    else:
        strings.append( (item, item) )

result = pscheduler.speccli_build_args(spec, 
                                       strings=strings,
                                       bools=bools)
pscheduler.succeed_json(result)




