Mercurial > hg > Lemuriformes
diff lemuriformes/cli.py @ 8:59c91bfb6c06
add basic CLI front-end
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sun, 10 Dec 2017 11:56:51 -0800 |
parents | |
children |
line wrap: on
line diff
--- /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))