from optparse import OptionParser
from oracle.oracle import Oracle
from user.user import User
from command import install,comp,compCrypto
import os
def main():
    os.system("clear")
    parser = OptionParser()

    parser.add_option("-i", "--installation", action="store_true", dest="installation", default=False, help="installation")
    parser.add_option("-o", "--oracle", action="store_true", dest="oracle", default=False, help="if true -> orcle will be run")
    parser.add_option("-u", "--user", action="store_true", dest="user", default=False, help="if true -> user will be run")
    parser.add_option("-s", "--server", dest="server", default="127.0.0.1", help="destination Server for feed data to Oracles")
    parser.add_option("-d", "--data", dest="data", default="", help="Data to send to destination server for response")
    parser.add_option("-b", "--broadcast", dest="broadcast", default="255.255.255.255", help="Broad cast IP")
    parser.add_option("-p", "--broadcast-port", dest="broadcastPort", default=6666, help="Broad cast Port")
    parser.add_option("-c", "--compile", dest="compile",  help="file compile")
    parser.add_option("-t", "--tls", dest="tls",  help="Crypto compile")
    # parser.add_option("-h", "--help",action="store_true", dest="help", default=False)



    (options, args) = parser.parse_args()



    if len(args) >= 1 or (options.oracle + options.user != 1 and not options.installation and not options.compile):
        print("\n\n\tWhat do you want to run? Oracle or User? \n\n\tplease use -o OR -u. \n\n\tFor more Info you can use -h or --help or i can do it for you\n \n\t~~~ GOOD LUCK :) ~~~\n")
        parser.print_help()
        return


    if(options.compile):
        comp(options.compile)
    if(options.tls):
        compCrypto(options.tls)

    if(options.installation):
        install()

    if(options.oracle):
        Oracle(broadcast=options.broadcast, broadcastPort=options.broadcastPort)
    
    if(options.user):
        User(data=options.data, server=options.server, broadcast=options.broadcast, broadcastPort=options.broadcastPort).run()

if __name__ == '__main__':
    main()
