summaryrefslogtreecommitdiff
path: root/megapixels/app/utils/click_utils.py
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2018-11-25 22:19:57 +0100
committerJules Laplace <julescarbon@gmail.com>2018-11-25 22:19:57 +0100
commite1fa31bfd6a938341c3a8a63f238d0952cf4b429 (patch)
treec61394d69022c026321a28cc0cf12c99208605c1 /megapixels/app/utils/click_utils.py
parentee3d0d98e19f1d8177d85af1866fd0ee431fe9ea (diff)
parent0529d4cd1618016319e995c37aa118bf8c2d501b (diff)
merge
Diffstat (limited to 'megapixels/app/utils/click_utils.py')
-rw-r--r--megapixels/app/utils/click_utils.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/megapixels/app/utils/click_utils.py b/megapixels/app/utils/click_utils.py
new file mode 100644
index 00000000..dc00f58c
--- /dev/null
+++ b/megapixels/app/utils/click_utils.py
@@ -0,0 +1,62 @@
+"""
+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))
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+