Mercurial > hg > tvii
comparison tvii/cli.py @ 75:a17d43d7bf1b
add simple CLI abstraction
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sun, 17 Dec 2017 13:32:24 -0800 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
74:e21021ca3907 | 75:a17d43d7bf1b |
---|---|
1 """ | |
2 Command-Line Interface support | |
3 """ | |
4 | |
5 import argparse | |
6 import os | |
7 | |
8 | |
9 class CLIParser(argparse.ArgumentParser): | |
10 """ABC for CLI parsing""" | |
11 | |
12 def __init__(self, **kwargs): | |
13 argparse.ArgumentParser.__init__(self, **kwargs) | |
14 self.add_arguments() | |
15 self.options = None | |
16 | |
17 def add_arguments(self): | |
18 self.add_argument('-v', '--verbose', dest='verbose', | |
19 action='store_true', default=False, | |
20 help="be more verbose") | |
21 | |
22 def parse_args(self, args): | |
23 | |
24 options = argparse.ArgumentParser.parse_args(self, args) | |
25 self.options = self.validate(options) | |
26 return self.options | |
27 | |
28 def validate(self, options): | |
29 | |
30 if not getattr(options, 'verbose', False): | |
31 # https://github.com/tensorflow/tensorflow/issues/7778 | |
32 os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' | |
33 | |
34 return options |