#! /usr/bin/env python
import flfl
import flfl.flflutil
import sys

def main(argv):
    from optparse import OptionParser

    usage = "usage: %prog [options] xml source"
    parser = OptionParser(usage=usage, version='%%prog %s' % flfl.__version__)
    parser.set_defaults(filename=None, asm=False, xml=False, configpath=None, swfmillcmd=None, flasmcmd=None)
    parser.add_option('-f', '--config-file', dest='configpath',
                      help='config file', metavar='CONFIG_FILE')
    parser.add_option('--swfmill', dest='swfmillcmd',
                      help='swfmill command')
    parser.add_option('--flasmcmd', dest='flasmcmd',
                      help='flasm command')
    parser.add_option("-o", dest="filename",
                      help="output FILE", metavar="FILE")
    parser.add_option("-S",
                      action="store_true", dest="asm",
                      help="Compile Only")
    parser.add_option("-X",
                      action="store_true", dest="xml",
                      help="XML Convert Only")

    (opt, args) = parser.parse_args()
    if len(args)<2:
        parser.print_help()
        parser.exit()

    flfl.flflutil.checkConfigPath()
    fname = opt.filename
    flfl.flflutil.mkswf(xmlpath=args[0], sourcepath=args[1],
                        flasmcmd=opt.flasmcmd, swfmillcmd=opt.swfmillcmd,
                        configpath=opt.configpath,
                        output=fname, asmf=opt.asm, xmlf=opt.xml)

main(sys.argv)
