diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2019-04-15 14:43:57 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2019-04-15 14:43:57 +0200 |
| commit | e257e83f313a2976347b0a30f58e66b7bcbc1235 (patch) | |
| tree | 5f579594ca61f5ea6f8495187aa6eee65e670590 /check/app/utils | |
| parent | 229ddbb5cbf228b13b44ecaa10ef931c68b97e5c (diff) | |
run flask
Diffstat (limited to 'check/app/utils')
| -rw-r--r-- | check/app/utils/click_utils.py | 43 |
1 files changed, 43 insertions, 0 deletions
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)) |
