handle no params

This commit is contained in:
Jack 2016-09-15 15:04:42 -04:00
parent e9a1dbca4b
commit 7b84d9b10a

View file

@ -36,18 +36,18 @@ def main():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('method', nargs=1, type=str) parser.add_argument('method', nargs=1, type=str)
parser.add_argument('params', nargs="+") parser.add_argument('params', nargs=argparse.REMAINDER, default=None)
args = parser.parse_args() args = parser.parse_args()
meth = args.method[0] meth = args.method[0]
params = {} params = {}
if args.params: if args.params:
if len(args.params) != 1: if len(args.params) > 1:
for i in args.params: for i in args.params:
k, v = i.split('=')[0], i.split('=')[1:] k, v = i.split('=')[0], i.split('=')[1:]
if isinstance(v, list): if isinstance(v, list):
v = ''.join(v) v = ''.join(v)
params[k] = guess_type(v) params[k] = guess_type(v)
else: elif len(args.params) == 1:
try: try:
params = json.loads(args.params[0]) params = json.loads(args.params[0])
except ValueError: except ValueError: