Mercurial > hg > Lemuriformes
changeset 8:59c91bfb6c06
add basic CLI front-end
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sun, 10 Dec 2017 11:56:51 -0800 |
parents | 92ae11e33f85 |
children | b69efcf85807 |
files | lemuriformes/cli.py |
diffstat | 1 files changed, 39 insertions(+), 0 deletions(-) [+] |
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))