From a2e028fd1923a19e5aa6e7031790bb04df431843 Mon Sep 17 00:00:00 2001 From: Tomas Korbar Date: Tue, 15 Jan 2019 19:18:15 +0100 Subject: [PATCH] Move validation of CHEAT_HIGHLIGHT value to Configuration class Method _check_configuration should be used for validating all bad values from now on --- bin/cheat | 10 ---------- cheat/configuration.py | 15 ++++++++++++++- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/bin/cheat b/bin/cheat index 2c15439..a95d592 100755 --- a/bin/cheat +++ b/bin/cheat @@ -46,16 +46,6 @@ 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') diff --git a/cheat/configuration.py b/cheat/configuration.py index 5062b82..cf3e14e 100644 --- a/cheat/configuration.py +++ b/cheat/configuration.py @@ -28,7 +28,7 @@ class Configuration: merged_config.update(self._read_env_vars_config()) - + self._check_configuration(merged_config) return merged_config @@ -65,6 +65,19 @@ class Configuration: return read_config + def _check_configuration(self, config): + """ Check values in config and warn user or die """ + + # validate CHEAT_HIGHLIGHT values if set + colors = [ + 'grey' , 'red' , 'green' , 'yellow' , + 'blue' , 'magenta' , 'cyan' , 'white' , + ] + if ( + config.get('CHEAT_HIGHLIGHT') and + config.get('CHEAT_HIGHLIGHT') not in colors + ): + Utils.die("%s %s" %('CHEAT_HIGHLIGHT must be one of:', colors)) def _read_env_var(self,current_config,key): if (os.environ.get(key)):