#!/usr/bin/env python3
# -------------------------------------------------------------------------------
# imports
# -------------------------------------------------------------------------------
import time
import argparse
import zmq   # pip install pyzmq

# -------------------------------------------------------------------------------
# main program
# -------------------------------------------------------------------------------
if __name__ == '__main__':
    # -------------------------------------------------------------------------------
    # parse the command line
    # -------------------------------------------------------------------------------
    parser = argparse.ArgumentParser(description='Orchestrate the autonomous secure operation of tradegen processes')

    # position argument
    parser.add_argument("command", help="specify the command you want to run", type=str)

    # optional arguments
    parser.add_argument('-p', '--port', type=int, default=8899,
                        help="Specify the port number for communication channel(socket). By default is '{}'".format(8899))
    parser.add_argument('-c', '--commands', type=str, default='shutdown',
                        help="Space separated commands that will be accepted by this program. By default is '{}'.".format('shutdown loader cleaner'))

    args = parser.parse_args()
    command = args.command

    context = zmq.Context()
    socket = context.socket(zmq.PUB)
    socket.bind("tcp://*:{}".format(args.port))

    time.sleep(1)
    print("Sending command {}".format(command))
    socket.send_string(command)
