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`.
This commit is contained in:
Chris Lane 2019-01-11 16:26:57 -05:00
parent 730c488854
commit 28a2902e20

View File

@ -37,10 +37,24 @@ Examples:
# require the dependencies # require the dependencies
from cheat import sheets, sheet from cheat import sheets, sheet
from cheat.utils import colorize from cheat.utils import colorize
from cheat.utils import die
from docopt import docopt from docopt import docopt
import os
if __name__ == '__main__': 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 # parse the command-line options
options = docopt(__doc__, version='cheat 2.3.1') options = docopt(__doc__, version='cheat 2.3.1')