# HG changeset patch # User Jeff Hammel # Date 1513546344 28800 # Node ID a17d43d7bf1bc4eb951a0b38db0f5a9adc1357ec # Parent e21021ca3907136d80504c67818957a950cd8a5a add simple CLI abstraction diff -r e21021ca3907 -r a17d43d7bf1b tvii/cli.py --- /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