changeset 75:a17d43d7bf1b

add simple CLI abstraction
author Jeff Hammel <k0scist@gmail.com>
date Sun, 17 Dec 2017 13:32:24 -0800
parents e21021ca3907
children 02f586a9defe
files tvii/cli.py
diffstat 1 files changed, 34 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tvii/cli.py	Sun Dec 17 13:32:24 2017 -0800
@@ -0,0 +1,34 @@
+"""
+Command-Line Interface support
+"""
+
+import argparse
+import os
+
+
+class CLIParser(argparse.ArgumentParser):
+    """ABC for CLI parsing"""
+
+    def __init__(self, **kwargs):
+        argparse.ArgumentParser.__init__(self, **kwargs)
+        self.add_arguments()
+        self.options = None
+
+    def add_arguments(self):
+        self.add_argument('-v', '--verbose', dest='verbose',
+                          action='store_true', default=False,
+                          help="be more verbose")
+
+    def parse_args(self, args):
+
+        options = argparse.ArgumentParser.parse_args(self, args)
+        self.options = self.validate(options)
+        return self.options
+
+    def validate(self, options):
+
+        if not getattr(options, 'verbose', False):
+            # https://github.com/tensorflow/tensorflow/issues/7778
+            os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
+
+        return options