comparison 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
comparison
equal deleted inserted replaced
7:92ae11e33f85 8:59c91bfb6c06
1 """
2 methods and properties supporting
3 command line interface
4 """
5
6
7 import argparse
8 import sys
9 from .cast import keyvalue
10
11
12 class ConfigurationParser(argparse.ArgumentParser):
13 """parse arguments with validation"""
14
15 def __init__(self, **kwargs):
16 kwargs.setdefault('formatter_class', argparse.RawTextHelpFormatter)
17 argparse.ArgumentParser.__init__(self, **kwargs)
18 self.add_arguments()
19 self.options = None
20
21 def add_arguments(self):
22 """add arguments"""
23 # Abstract Base Class
24
25 def parse_args(self, args=sys.argv[1:]):
26 options = argparse.ArgumentParser.parse_args(self, args)
27 self.options = self.validate(options)
28 return self.options
29
30 def validate(self, options):
31 """validate options"""
32 return options
33
34 def keyvalue(self, arg):
35
36 try:
37 return keyvalue(arg)
38 except AssertionError as e:
39 self.error(str(e))