#!/usr/bin/env python

# An OMHE Microsyntax parser command line utility.
# Alan Viars, Videntity 2010-2012

import os, sys
from omhe.core.parseomhe import parseomhe


if __name__ == "__main__":    
    """
    Accept a singe omhe string from the command line. Parse, then print
    the resulting dict as JSON to stout.
    """
    try: 
        omhe_str=sys.argv[1]
    except(IndexError):
        print "Erros: You must supply an OMHE message!"
        exit(1)
        
    try:
        """ Instantaiate an instance of the parseomhe class"""        
	p = parseomhe()
        """Parse it if valid, otherwise raise the appropriate  error"""
        d=p.parse(omhe_str)
        """convvert to json"""
	j=p.omhedict2json(d)
	print j

    except():
        print "An unexpected error occured. Here is the post-mortem:"
        print sys.exc_info()