From b5bf80521dfa2bc8a44ec6330da5d383b46e79a1 Mon Sep 17 00:00:00 2001 From: packocrayons Date: Wed, 6 Dec 2017 13:49:34 -0500 Subject: [PATCH] cliRPL supports interactive mode when called with the -i flag. Original functionality is maintained --- cliRPL.py | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/cliRPL.py b/cliRPL.py index ec61b5e..34b922e 100644 --- a/cliRPL.py +++ b/cliRPL.py @@ -33,7 +33,7 @@ def usage(): return usage if __name__ == '__main__': - if len(sys.argv) != 2: + if len(sys.argv) < 2: # If there's less than two arguments, the first being the name of the program, there can't possibly be a command print usage() sys.exit(-1) @@ -41,9 +41,28 @@ def usage(): cli_sock = context.socket(zmq.REQ) cli_sock.connect("ipc://RPL_CLI") - try: - cli_sock.send(sys.argv[1], zmq.DONTWAIT) - except zmq.ZMQError, err: - print "unable to communicate with the simpleRPL daemon: %s" % err - sys.exit(-1) - print cli_sock.recv() + interactive = False + + if sys.argv[1] == '-i': # Interactive mode is requested + interactive = True + else: + try: + cli_sock.send(sys.argv[1], zmq.DONTWAIT) + except zmq.ZMQError, err: + print "unable to communicate with the simpleRPL daemon: %s" % err + sys.exit(-1) + print cli_sock.recv() + + + while interactive: + command = raw_input("cliRPL > ") + if command == 'exit': + interactive = False + break + try: + print command + cli_sock.send(command, zmq.DONTWAIT) + except zmq.ZMQError, err: + print "unable to communicate with the simpleRPL daemon: %s" % err + sys.exit(-1) + print cli_sock.recv()