# HG changeset patch # User Jeff Hammel # Date 1512935811 28800 # Node ID 59c91bfb6c06aad5cb638bb77ab356c3fe29fcbb # Parent 92ae11e33f85596f34ce458d2dc62aeb3857cabb add basic CLI front-end diff -r 92ae11e33f85 -r 59c91bfb6c06 lemuriformes/cli.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lemuriformes/cli.py Sun Dec 10 11:56:51 2017 -0800 @@ -0,0 +1,39 @@ +""" +methods and properties supporting +command line interface +""" + + +import argparse +import sys +from .cast import keyvalue + + +class ConfigurationParser(argparse.ArgumentParser): + """parse arguments with validation""" + + def __init__(self, **kwargs): + kwargs.setdefault('formatter_class', argparse.RawTextHelpFormatter) + argparse.ArgumentParser.__init__(self, **kwargs) + self.add_arguments() + self.options = None + + def add_arguments(self): + """add arguments""" + # Abstract Base Class + + def parse_args(self, args=sys.argv[1:]): + options = argparse.ArgumentParser.parse_args(self, args) + self.options = self.validate(options) + return self.options + + def validate(self, options): + """validate options""" + return options + + def keyvalue(self, arg): + + try: + return keyvalue(arg) + except AssertionError as e: + self.error(str(e))