summaryrefslogtreecommitdiff
path: root/megapixels/app/utils/click_utils.py
diff options
context:
space:
mode:
authoradamhrv <adam@ahprojects.com>2018-11-04 21:44:20 +0100
committeradamhrv <adam@ahprojects.com>2018-11-04 21:44:20 +0100
commit156790b383101756e2324dcde63415f00ba94a86 (patch)
tree62761815f480d244fae3602c9189baf7aec02497 /megapixels/app/utils/click_utils.py
parent83507e26c00f79b7bac3d3b606da50cc4cd0db6b (diff)
.
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))
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+