From e257e83f313a2976347b0a30f58e66b7bcbc1235 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 15 Apr 2019 14:43:57 +0200 Subject: run flask --- check/app/utils/click_utils.py | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 check/app/utils/click_utils.py (limited to 'check/app/utils') diff --git a/check/app/utils/click_utils.py b/check/app/utils/click_utils.py new file mode 100644 index 0000000..fe69a6b --- /dev/null +++ b/check/app/utils/click_utils.py @@ -0,0 +1,43 @@ +""" +Custom Click parameter types +""" +import click + +from app.settings import app_cfg as cfg +from app.settings import types + + +# -------------------------------------------------------- +# Click command helpers +# -------------------------------------------------------- +def enum_to_names(enum_type): + return {x.name.lower(): x for x in enum_type} + +def show_help(enum_type): + names = enum_to_names(enum_type) + return 'Options: "{}"'.format(', '.join(list(names.keys()))) + +def get_default(opt): + return opt.name.lower() + + +# -------------------------------------------------------- +# Custom Click parameter class +# -------------------------------------------------------- + + +class ParamVar(click.ParamType): + + name = 'default_type' + + def __init__(self, param_type): + # self.name = '{}'.format(param_type.name.lower()) + # sealf. + self.ops = {x.name.lower(): x for x in param_type} + + def convert(self, value, param, ctx): + """converts (str) repr to Enum hash""" + try: + return self.ops[value.lower()] + except: + self.fail('{} is not a valid option'.format(value, param, ctx)) -- cgit v1.2.3-70-g09d2