From 28a2902e2084c6d8c55926fd432598f4baca93c6 Mon Sep 17 00:00:00 2001 From: Chris Lane Date: Fri, 11 Jan 2019 16:26:57 -0500 Subject: [PATCH] Implemented validation on CHEAT_HIGHLIGHT Implemnted an assertion that `CHEAT_HIGHLIGHT` (if set) contains a value that is acceptible to `termcolors`. This happens only once, upon the invokation of `__main__`. If the assertion fails, `cheat` terminates with an exit code of `1`. --- bin/cheat | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/bin/cheat b/bin/cheat index 0e7fb7c..08ccaa6 100755 --- a/bin/cheat +++ b/bin/cheat @@ -37,10 +37,24 @@ Examples: # require the dependencies from cheat import sheets, sheet from cheat.utils import colorize +from cheat.utils import die from docopt import docopt +import os if __name__ == '__main__': + + # validate CHEAT_HIGHLIGHT values if set + colors = [ + 'grey' , 'red' , 'green' , 'yellow' , + 'blue' , 'magenta' , 'cyan' , 'white' , + ] + if ( + os.environ.get('CHEAT_HIGHLIGHT') and + os.environ.get('CHEAT_HIGHLIGHT') not in colors + ): + die("%s %s" %('CHEAT_HIGHLIGHT must be one of:', colors)) + # parse the command-line options options = docopt(__doc__, version='cheat 2.3.1')