Mercurial > hg > Lemuriformes
view lemuriformes/cli.py @ 16:9b1bb9eee962
misc functions related to filesystem paths
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sun, 10 Dec 2017 17:19:30 -0800 |
parents | 59c91bfb6c06 |
children |
line wrap: on
line source
""" 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))